Ampelofilosofies

homeaboutrss
The mind is like a parachute. If it doesn't open, you're meat.

ForgetMeNot: Jenkins Pipeline Jobs polling SCM changes

05 Mar 2017

It took me a disproportionate amount of time and significant reserves of google foo to figure this out, so it merits documentation.

The Problem

I use a setup that involves creating all jobs via JobDSL definitions and have several jobs leveraging the PipelineDSL.

It was unclear how to tell the git which repo to poll, which credentials to use etc.

Just a warning: none of the options to the scm trigger in JobDSL work for a pipeline job.

You just define a plain, dumb scm poll in the frequency you require, for example:

triggers {
  scm 'H(3) * * * 1-5'
}

What works?

The rest of information is passed to git in the Pipeline definition.

node(){
  git changelog: true, credentialsId: 'bla-bla-bla', poll: true, url: 'https://url.to.repo', branch: brnch  
}

The critical part here is setting poll to true. The job will trigger, enter the pipeline and then setup polling for any future job invocations. I tend to set changelog to true as well, because if we’re going to pay the penalty (see further down) we might as well get as much as possible out of it.

Handicap

I find this approach problematic, since it requires us to have a workspace (so we need a node() context in the pipeline) and we need to clone the repo.

In my case this is exarcebated by bad repository care practices (lots of binary data commited makes the repo way to large relative to it’s content). Also, I tend to structure pipelines with simple jobs (things like Build Module, Test Module, Package & Publish) that are then strung together as a pipeline and the composite jobs usually do not need a workspace. So this cloning is really pure overhead.

If anyone knows how to get polling working without requiring a full clone, please have a go at the comments.

blog comments powered by Disqus