Triggering pipeline builds when a commit is pushed to a branch or when a tag that matches a regex is pushed.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Triggering pipeline builds when a commit is pushed to a branch or when a tag that matches a regex is pushed.

Francis Chuang
Hey all,

I have a question with configuring Jenkins that I have been struggling
with for a while. We are using Jenkins 2.150.1.

My jenkinsfile looks like this:
pipeline {
     agent {
         node {
             label 'some-node'
         }
     }

     environment {
         COMPOSE_PROJECT_NAME = "${env.JOB_NAME}-${env.BUILD_ID}"
     }

     options {
         timeout(time: 40, unit: 'MINUTES')
     }

     stages {
         stage('Build Site') {
             when {
                 branch 'test-site'
             }
             steps {
                 ...
             }
         }

         stage('Build Javadoc') {
                        when {
                                buildingTag()
                        }
             steps {
                 ...
             }
         }

         stage('Deploy Site') {
             when {
                 branch 'test-site'
             }
             steps {
                ...
         }

         stage('Deploy Javadoc') {
                        when {
                                buildingTag()
                        }
             steps {
                 ...
             }
         }
     }
     post {
         always {
             sh 'docker system prune --force --all'
         }
     }
}

I want to run a pipeline when a commit is pushed to a branch. I am able
to do this by setting "Branches to build" to `refs/heads/test-site`.

However, I also need to build a pipeline when a tag that matches a regex
is pushed. I tried adding a refspec following
https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/136740885/Triggering+Jenkins+Based+on+New+Tags 
, however it doesn't trigger the build.

Does anyone have any tips for how to get this to work?

Francis

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/77c2a45c-6283-6eb6-2baa-6ff929e70d20%40apache.org.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Triggering pipeline builds when a commit is pushed to a branch or when a tag that matches a regex is pushed.

Tomas Bjerre
Have you seen Generic Webhook Trigger Plugin? https://github.com/jenkinsci/generic-webhook-trigger-plugin

Exact usage depends on what Git service you are using. If it is GitHub you may have a look at this:
https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github/github-push-specific-branches.feature

Den måndag 15 juli 2019 kl. 01:38:04 UTC+2 skrev Francis Chuang:
Hey all,

I have a question with configuring Jenkins that I have been struggling
with for a while. We are using Jenkins 2.150.1.

My jenkinsfile looks like this:
pipeline {
     agent {
         node {
             label 'some-node'
         }
     }

     environment {
         COMPOSE_PROJECT_NAME = "${env.JOB_NAME}-${env.BUILD_ID}"
     }

     options {
         timeout(time: 40, unit: 'MINUTES')
     }

     stages {
         stage('Build Site') {
             when {
                 branch 'test-site'
             }
             steps {
                 ...
             }
         }

         stage('Build Javadoc') {
                        when {
                                buildingTag()
                        }
             steps {
                 ...
             }
         }

         stage('Deploy Site') {
             when {
                 branch 'test-site'
             }
             steps {
                ...
         }

         stage('Deploy Javadoc') {
                        when {
                                buildingTag()
                        }
             steps {
                 ...
             }
         }
     }
     post {
         always {
             sh 'docker system prune --force --all'
         }
     }
}

I want to run a pipeline when a commit is pushed to a branch. I am able
to do this by setting "Branches to build" to `refs/heads/test-site`.

However, I also need to build a pipeline when a tag that matches a regex
is pushed. I tried adding a refspec following
<a href="https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/136740885/Triggering+Jenkins+Based+on+New+Tags" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmohamicorp.atlassian.net%2Fwiki%2Fspaces%2FDOC%2Fpages%2F136740885%2FTriggering%2BJenkins%2BBased%2Bon%2BNew%2BTags\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFhvWOGtL-Q4ERSm_1tNsL04Bx5tA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmohamicorp.atlassian.net%2Fwiki%2Fspaces%2FDOC%2Fpages%2F136740885%2FTriggering%2BJenkins%2BBased%2Bon%2BNew%2BTags\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFhvWOGtL-Q4ERSm_1tNsL04Bx5tA&#39;;return true;">https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/136740885/Triggering+Jenkins+Based+on+New+Tags
, however it doesn't trigger the build.

Does anyone have any tips for how to get this to work?

Francis

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7494d2c3-2f23-4695-b0f1-90b57e9b6a69%40googlegroups.com.