Jenkins workflow (pipeline) - build job only when there are SCM changes -


i'm creating quite complicated workflow using workflow-plugin (renamed pipeline plugin). simplicity let's assume need build job, job quite expensive , doesn't need build every time. when there scm changes.

so let's call job expensivejob , it's source code management there scmrepositorya.

so want

build job: 'expensivejob' 

and want poll scm changes , build job based on information.

is there way how this?

my current solution have checkout in pipeline script scmrepositorya , check currentbuild.rawbuild.changesets seems me quite lot of unnecessary work , possibly have align whatever source code management changes in jobs..

there not equivalent of build step merely initiate polling, opposed unconditionally scheduling build.

writing such step, or making option of build step, not particularly difficult think. in meantime, non-sandboxed script, same direct jenkins api calls: if downstream project had configured scm trigger (need poll @daily, or have no schedule @ all), then

jenkins.instance.getitembyfullname('downstream').scmtrigger.run() 

would suffice schedule polling (untested). alternately, if wanted run polling directly, or did not want assume blank `scmtrigger, then

if (jenkins.instance.getitembyfullname('downstream').poll(tasklistener.null).haschanges()) {     build 'downstream' } 

(again untested) work. api calls need wrapped in @noncps method, though, since intermediate results not serializable:

if (poll('downstream')) {     build 'downstream' } @noncps boolean poll(string job) {     jenkins.instance.getitembyfullname(job).poll(tasklistener.null).haschanges() } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -