Run pipeline only when new commits for a specific tag

48 views
Skip to first unread message

Stefano Tranquillini

unread,
Mar 23, 2017, 5:45:05 AM3/23/17
to Jenkins Users
Hi all,

i've a pipeline that runs for my code, now, I work with Bitbucket and I found a way to start the pipeline via the webhook, the problem is that it builds every push, which I don't want.
What I would like is that it build everythime the tag "develop" is pushed to the remote and there are new commits.
The BitBucket webhook is raised every push, so I need to modify the pipe in order to avoid building if there are no new commits in that speciic tag.

node{
    properties
([disableConcurrentBuilds(), buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')), parameters([string(defaultValue: '...', description: '', name: 'CUSTOMER_ID'), string(defaultValue: 'Develop', description: '', name: 'BUILD_ID'), string(defaultValue: '...', description: '', name: 'CUSTOMER_KEY')])], pipelineTriggers([[$class: 'BitBucketTrigger']])

stage
('checkout'){
            checkout
([$class: 'GitSCM', branches: [[name: '*/tags/develop']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '.....', refspec: '+refs/tags/*:refs/remotes/origin/tags/*', url: 'REMOTEURL']]])
       
}

        stage
('setup'){
....

}
}

How can I write an If for the checkout to say: exit if there are new commits or keep going if there's a new commit compared to last build??

PS: if i will have tags with version, so develop-1 develop-2, and I'll change the branch to '*/tags/develop*' which branch will be built?


Cuong Tran

unread,
Mar 23, 2017, 11:40:20 AM3/23/17
to Jenkins Users
Tags are mostly read-only, so I'm not sure what you're trying to do with "detect new commits" in specific tag.  You can probably say "trigger builds for any new tag that matches tags/develop/*" and your tags have to be "develop/v1", "develop/v2", etc.

Stefano Tranquillini

unread,
Mar 24, 2017, 3:52:09 AM3/24/17
to jenkins...@googlegroups.com
i move the tag to the commit i want. the fact is that i can use the tag. but if i trigger the pipeline every commit it will build even if the tag. commit is it changed. right? 

if i've v1 v2 etc. which build will jenkins do? all?
--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/hMNSQ_Q6pQU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a81f4ec6-8b37-414f-9838-765ca44de431%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Stefano - Sent with my thumbs
Reply all
Reply to author
Forward
0 new messages