[JIRA] (JENKINS-55987) Use of when buildingTag does not work in Declarative pipeline

141 views
Skip to first unread message

dominique.tronche@atos.net (JIRA)

unread,
Feb 6, 2019, 3:43:02 AM2/6/19
to jenkinsc...@googlegroups.com
Tronche Dominique created an issue
 
Jenkins / Bug JENKINS-55987
Use of when buildingTag does not work in Declarative pipeline
Issue Type: Bug Bug
Assignee: Unassigned
Attachments: jenkins-console-output.log
Components: pipeline
Created: 2019-02-06 08:42
Environment: docker environment
Priority: Minor Minor
Reporter: Tronche Dominique

For our project we are using gitlab-ce and Jenkins to build docker images. I'm using a Pipeline Jenkinsfile to build my docker
I suppose my jenkins job is correctly configured since the build is triggered each time I push a commit or a tag into my gitlab project
In my pipeline, I have a stage I wish to be called only when a tag is pushed (git push --tag)
I added the following line
{{when { buildingTag() }}}
But every time I push a tag in gitlab, I have the message Stage skipped due to when conditional

Here is the Jenkinsfile I'm using:

 

pipeline {
{{   agent any }}
   stages {
     stage('Build') {
      steps {
         gitlabCommitStatus(name:"build") {
{{         script { }}
           docker.withRegistry('Nexus URL', 'docker-pull-id') {
{{              app = docker.build("my-project","--my proxy options") }}
{{           }}}
{{         }}}
        } 
{{       }}}
{{     }}}
     stage('Push image') {
       steps {
{{         script { }}
           docker.withRegistry('Nexus URL', 'docker-push-id') {
           app.push("latest")
{{         }}}
{{        }}}
{{      }}}
{{     }}}
     stage('Push tag image') {
{{       when { buildingTag() }}}
        steps {
{{          script { }}
{{             docker.withRegistry('Nexus URL', 'docker-pull-id')') {}}
               app.push("tag")
{{            }}}
{{          }}}
{{       }}}
{{    }}}
{{  }}}
}

Context

{{}}

  • Gitlab plugin version: 1.5.11
  • Gitlab CE version: 11.2.0
  • Jenkins version: 2.163
  • Job type: Pipeline (the pipeline plugins are up to date)

Our Jenkins docker container is based on image jenkins/jenkins:2.163-alpine

Attached the console output triggered when after the push of a tag using the command:

git push --tag origin master

{{}}

{{}}

Is there something special to do to use the when tag or when buildingTag ? It seems to me I have done everything according to the documentation{{}}

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

dominique.tronche@atos.net (JIRA)

unread,
Feb 7, 2019, 4:27:02 AM2/7/19
to jenkinsc...@googlegroups.com
Tronche Dominique updated an issue
Change By: Tronche Dominique
For our project we are using gitlab-ce and Jenkins to build docker images. I'm using a Pipeline Jenkinsfile to build my docker
I suppose my jenkins job is correctly configured since the build is triggered each time I push a commit or a tag into my gitlab project
In my pipeline, I have a stage I wish to be called only when a tag is pushed (git push --tag)
I added the following line
\ {{when \
{  buildingTag() }}}
But every time I push a tag in gitlab, I have the message _Stage skipped due to when conditional_


Here is the Jenkinsfile I'm using:

 

{{pipeline { }}
{{   agent any }}
{{  

stages { }}
{{     stage('Build') { }}
{{      steps { }}
{{         gitlabCommitStatus(name:"build") { }}
{{         script { }}
{{          

docker.withRegistry('Nexus URL', 'docker-pull-id') { }}
{{              app = docker.build("my-project","--my proxy options")
} }
{{           } }}
{{         }
} }
{{        }  }}
{{       }}}
{{     }}}
{{    
stage('Push image') { }}
{{       steps { }}
{{         script { }}
{{          

docker.withRegistry('Nexus URL', 'docker-push-id') { }}
{{           app.push("latest") }}
{{         } }}
{{        } }}
{{      } }}
{{     } }}
{{     stage('Push tag image') { }}
{{       when \ { buildingTag() } }}
{{        steps { }}
{{          script { }}
{{            

docker.withRegistry('Nexus URL', 'docker-pull-id')') { }}
{{               app.push("tag")
} }
{{            } }}
{{          } }}
{{       } }}
{{    } }}
{{  } }}
{{ }} }
 
h3. Context

{{}}
* *Gitlab plugin version*: 1.5.11
* *Gitlab CE version*: 11.2.0
* *Jenkins version*: 2.163
* *Job type*: Pipeline (the pipeline plugins are up to date)


Our Jenkins docker container is based on image jenkins/jenkins:2.163-alpine

Attached the console output triggered when after the push of a tag using the command:

{{git push --tag origin master}}

{{}}

{{}}

Is there something special to do to use the _when tag_ or _when buildingTag_ ? It seems to me I have done everything according to the documentation \ {{}}

dominique.tronche@atos.net (JIRA)

unread,
Feb 7, 2019, 4:28:02 AM2/7/19
to jenkinsc...@googlegroups.com

dominique.tronche@atos.net (JIRA)

unread,
Feb 7, 2019, 4:29:01 AM2/7/19
to jenkinsc...@googlegroups.com
Tronche Dominique updated an issue
Change By: Tronche Dominique
Attachment: Jenkinsfile
{{ For our project we are using gitlab-ce and Jenkins to build docker images. I'm using a Pipeline Jenkinsfile to build my docker }}
{{ I suppose my jenkins job is correctly configured since the build is triggered each time I push a commit or a tag into my gitlab project }}
{{ In my pipeline, I have a stage I wish to be called only when a tag is pushed (git push --tag) }}
{{ I added the following line }}
{{when


}} { {{ buildingTag() }}}


But every time I push a tag in gitlab, I have the message _Stage skipped due to when conditional_

Here is

Attached
the Jenkinsfile I'm using :

dominique.tronche@atos.net (JIRA)

unread,
Feb 7, 2019, 4:31:02 AM2/7/19
to jenkinsc...@googlegroups.com
Tronche Dominique updated an issue
{{For our project we are using gitlab-ce and Jenkins to build docker images. I'm using a Pipeline Jenkinsfile to build my docker}}
{{ I suppose my jenkins job is correctly configured since the build is triggered each time I push a commit or a tag into my gitlab project }}
{{   In my pipeline, I have a stage I wish to be called only when a tag is pushed (git push --tag)}}
{{ I added the following line }} :
{{    when }}

     \
{ {{ buildingTag() } }}

 

But every time I push a tag in gitlab, I have the message _Stage skipped due to when conditional_

Attached the Jenkinsfile I'm using
h3. Context
* *Gitlab plugin version*: 1.5.11
* *Gitlab CE version*: 11.2.0
* *Jenkins version*: 2.163
* *Job type*: Pipeline (the pipeline plugins are up to date)

Our Jenkins docker container is based on image jenkins/jenkins:2.163-alpine

Attached the console output triggered when after the push of a tag using the command:

{{git push --tag origin master}}

 

 

Is there something special to do to use the _when tag_ or _when buildingTag_ ? It seems to me I have done everything according to the documentation
\{{}}

connor@dotconnor.com (JIRA)

unread,
May 11, 2019, 2:06:03 AM5/11/19
to jenkinsc...@googlegroups.com

cristian.calin.rat@gmail.com (JIRA)

unread,
Aug 16, 2019, 10:25:02 AM8/16/19
to jenkinsc...@googlegroups.com

cristian.calin.rat@gmail.com (JIRA)

unread,
Aug 16, 2019, 10:25:03 AM8/16/19
to jenkinsc...@googlegroups.com

raspy27@gmail.com (JIRA)

unread,
Dec 5, 2019, 5:27:03 AM12/5/19
to jenkinsc...@googlegroups.com

Attached log misses the important output of actual cloning so it's impossible to verify, but most times it's because you are not actually building a tag. You need to check out the tag (i.e. by starting build from the Tags tab of a multibranch pipeline) to make those conditions work. It is not enough to just build a commit that happens to have tags applied. Make sure that the Checking out Revision line (not included in attached output) lists a tag, not a branch.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

dominique.tronche@atos.net (JIRA)

unread,
Dec 5, 2019, 6:54:02 AM12/5/19
to jenkinsc...@googlegroups.com
Tronche Dominique updated an issue
Change By: Tronche Dominique
Attachment: jenkins-console-output-scm.log

dominique.tronche@atos.net (JIRA)

unread,
Dec 5, 2019, 7:02:03 AM12/5/19
to jenkinsc...@googlegroups.com
Tronche Dominique commented on Bug JENKINS-55987
 
Re: Use of when buildingTag does not work in Declarative pipeline

Thanks for the update. This bug is really blocking for our team since I cannot use Declarative pipeline in our project due to it

I have attached a log file with the detail start of the jenkins log file. The Checking out Revision indicates we are on a tag, yet the stage is skipped

I am not using a multibranch pipeline but a simple pipeline project. I did not see any limitation on the documentation on this subject. We are not planning to use multibranch pipelines since this item does not offer the "Build after other projects are built" option and we need it

dominique.tronche@atos.net (JIRA)

unread,
Dec 5, 2019, 7:03:02 AM12/5/19
to jenkinsc...@googlegroups.com
Tronche Dominique edited a comment on Bug JENKINS-55987
Thanks for the update. This bug is really blocking for our team since I cannot use Declarative pipeline in our project due to it

I have attached a log file with the detail start scm part of the jenkins log file. The Checking out Revision indicates we are on a tag, yet the stage is skipped


I am not using a multibranch pipeline but a simple pipeline project. I did not see any limitation on the documentation on this subject. We are not planning to use multibranch pipelines since this item does not offer the "Build after other projects are built" option and we need it

raspy27@gmail.com (JIRA)

unread,
Dec 5, 2019, 8:00:03 AM12/5/19
to jenkinsc...@googlegroups.com

Technically this condition checks for existence of environment variable called TAG_NAME. This is normally contributed by Branch API, for multibranch approach. If you don't use multibranching, you can try to populate TAG_NAME yourself before the condition, or just rework the condition.

dominique.tronche@atos.net (JIRA)

unread,
Dec 5, 2019, 8:25:02 AM12/5/19
to jenkinsc...@googlegroups.com

OK now I understand why it does not work but do we agree that this limitation is clearly not documented ?

I remembered I tried to do it myself but I had quite some trouble implementing it and it was very frustrating when there is supposed to be a function that do it for you.

Personally I don't really understand why this function, which is probably needed by a lot of people, is restricted to multibranch. Especially since multibranch does not allow project dependency which is a bit one of the main reason Jenkins is used for...

Thanks for your help anyway

Reply all
Reply to author
Forward
0 new messages