[JIRA] (JENKINS-55587) Env variables not available in pipeline options sections, outside of stages

3 views
Skip to first unread message

chad.geisler1@gmail.com (JIRA)

unread,
Jan 14, 2019, 6:07:01 PM1/14/19
to jenkinsc...@googlegroups.com
Chad Geisler created an issue
 
Jenkins / Bug JENKINS-55587
Env variables not available in pipeline options sections, outside of stages
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2019-01-14 23:06
Labels: pipeline
Priority: Major Major
Reporter: Chad Geisler

Environments variables such as ${env.NODE_NAME} are not available in Options {} before stages.  I want to dynamically lock a node using options {} before the first stage starts and keep that node locked for the entire pipeline. 

I have spent hours on this everything I tried returns NULL. I know I can lock each stage individually but that won't work for me since it releases that lock at the end of each stage.

options {
    lock (resource: "${env.NODE_NAME}")
    }
stages {
    stage("stage name") {
         steps {.....

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

andrew.bayer@gmail.com (JIRA)

unread,
Jan 17, 2019, 12:15:02 PM1/17/19
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
Change By: Andrew Bayer
Component/s: pipeline-model-definition-plugin
Component/s: pipeline

alexandre.fabra.fernandez@gmail.com (JIRA)

unread,
Dec 2, 2019, 4:15:02 PM12/2/19
to jenkinsc...@googlegroups.com
Alexandre Fabra Fernandez updated an issue
Change By: Alexandre Fabra Fernandez
Sprint: Declarative backlog
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

Luke.Lussenden@gmail.com (JIRA)

unread,
Mar 6, 2020, 4:36:02 PM3/6/20
to jenkinsc...@googlegroups.com
Luke Lussenden commented on Bug JENKINS-55587
 
Re: Env variables not available in pipeline options sections, outside of stages

I use the options style lock to wrap a few stages in a large pipeline and I have the same problem.  Even though the lock is deep within the pipeline, it seems the options are per-computed before the run and the ENV variables are not yet injected.   For my use case - I would really like to use the `GIT_URL` provided by the multibranch pipeline project as the source of my lock.  I don't mind multiple branches building at once, but there is a section they can't be in at the same time if they are on the same repo.
```groovy
stages {
     stage('do stuff 1'){}
     stage('do stuff 2'){}
     stage('locked set'){
        stages {
            options { lock(resource: "${GIT_URL}") }
            stage('first action set'){ }
            stage('second action set'){ }
        }
    }
    stage('do final stuff'){}
}
```

If you have a parameterized build - I believe parameters are available to the options blocks - but not environment variables.

This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

Luke.Lussenden@gmail.com (JIRA)

unread,
Mar 6, 2020, 4:38:03 PM3/6/20
to jenkinsc...@googlegroups.com
Luke Lussenden edited a comment on Bug JENKINS-55587
I use the options style lock to wrap a few stages in a large pipeline and I have the same problem.  Even though the lock is deep within the pipeline, it seems the options are per-computed before the run and the ENV variables are not yet injected.   For my use case - I would really like to use the `GIT_URL` provided by the multibranch pipeline project as the source of my lock.  I don't mind multiple branches building at once, but there is a section they can't be in at the same time if they are on the same repo.
``` {code: groovy }
stages {
     stage('do stuff 1'){}
     stage('do stuff 2'){}
     stage('locked set'){
        stages {
            options
\ { lock(resource: "${GIT_URL}") }

            stage('first action set')
\ { }

            stage('second action set')
\ { }

        }
    }
    stage('do final stuff'){}
} {code}
```

If you have a parameterized build - I believe parameters are available to the options blocks - but not environment variables.
Reply all
Reply to author
Forward
0 new messages