[JIRA] (JENKINS-43336) Allow locking multiple stages in declarative pipeline

2 views
Skip to first unread message

dragonia@gmx.at (JIRA)

unread,
Feb 12, 2018, 11:32:03 AM2/12/18
to jenkinsc...@googlegroups.com
Worry Darque commented on New Feature JENKINS-43336
 
Re: Allow locking multiple stages in declarative pipeline

Andrew Bayer I'm not so sure about this, as this only works if we would be allowed to wrap the substages inside an "lock" declaration, which, as of now, would be impossible as lock is not a valid direct child of a stage (has to be nested inside steps).

I tried

 

stage('Build Editor') {
    lock("myLock") {
        steps {
            //...
        }
    }
}

,

stage('Build Editor') {
    lock("myLock") {
        parallel {
            stage("ReallyBuild") {
                steps {
                    //...
                }
            }
        }
    }
}

 as well as 

stage('Build Editor') {
    parallel {
        lock("myLock") {
            stage("ReallyBuild") {
                steps {
                    //...
                }
            }
        }
    }
}

 to no avail, as it fails with

No "steps" or "parallel" to execute within stage

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Feb 12, 2018, 11:38:02 AM2/12/18
to jenkinsc...@googlegroups.com

JENKINS-46809 will give you what you need on top of what's already available from JENKINS-48380, so that you could do something like:

stage('Parent') {
  options {
    lock('myLock')
  }
  stages {
    stage('first child') {
      ...
    }
    stage('second child') {
      ...
    }
  }
}

dragonia@gmx.at (JIRA)

unread,
Feb 12, 2018, 11:39:02 AM2/12/18
to jenkinsc...@googlegroups.com
Worry Darque edited a comment on New Feature JENKINS-43336
[~abayer] I'm not so sure about this, as this only works if we would be allowed to wrap the substages inside an "lock" declaration, which, as of now, would be impossible as lock is not a valid direct child of a stage (has to be nested inside steps).

I tried

 
{code:java}

stage('Build Editor') {
    lock("myLock") {
        steps {
            //...
        }
    }
}
{code}
,
{code:java}

stage('Build Editor') {
    lock("myLock") {
        parallel {
            stage("ReallyBuild") {
                steps {
                    //...
                }
            }
        }
    }
}
{code}
 as well as 


{code:java}

stage('Build Editor') {
    parallel {
        lock("myLock") {
            stage("ReallyBuild") {
                steps {
                    //...
                }
            }
        }
    }
}
{code}

 to no avail, as it fails with
{quote}No "steps" or "parallel" to execute within stage
{quote}
 
or
{quote}No stages specified ...{quote}

vivek.pandey@gmail.com (JIRA)

unread,
Mar 13, 2018, 12:09:41 PM3/13/18
to jenkinsc...@googlegroups.com
Vivek Pandey updated an issue
 
Jenkins / New Feature JENKINS-43336
Change By: Vivek Pandey
Sprint: Declarative - 1.2 , Pipeline - Candidates

rrueth@gmail.com (JIRA)

unread,
Feb 16, 2019, 1:14:03 PM2/16/19
to jenkinsc...@googlegroups.com
Ryan Rueth commented on New Feature JENKINS-43336
 
Re: Allow locking multiple stages in declarative pipeline

Andrew Bayer, I'm trying to lock multiple stages based on the Jenkins node on which the stages will execute. It seems like the only way to do this is using the `options` block that you specified:

stage('Parent') {
  options {
    lock("${env.NODE_NAME}")
  }
  stages {
    stage('first child') {
      ...
    }
    stage('second child') {
      ...
    }
  }
}

Unfortunately, the resource this attempts to lock is `null`:

Trying to acquire lock on [null]

 

It appears that this won't work because the stage's `options` directive occurs before entering the agent. The declarative pipeline syntax  documentation says: 

Inside a stage, the steps in the options directive are invoked before entering the agent or checking any when conditions.

 
Is there any way to lock multiple stages for a single env.NODE_NAME?  Ideally, other subsequent stages could still run in parallel with other builds (i.e. so limiting executors to 1 or disabling concurrent builds are not options).
 

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

nikolodus@gmail.com (JIRA)

unread,
Mar 7, 2019, 1:52:03 PM3/7/19
to jenkinsc...@googlegroups.com

Just wanted to +1 on Ryan Rueth's comment regarding locking multiple stages with lock named after $NODE_NAME. Pretty much in the same situation, and I'd like to know if this can be supported - either by enabling options block to execute after agent has been assigned for a given stage, or through some other means if this is not an option.

Andrew Bayer do you know if this could be possible?

philipp.abraham@innogames.com (JIRA)

unread,
Apr 3, 2019, 9:26:03 AM4/3/19
to jenkinsc...@googlegroups.com

`env` ist not available in options but you could try getting the node name from the API:

```

stage('Parent') {
   options {
     lock("${currentBuild.getRawBuild().getExecutor().getOwner().getDisplayName()}")


   }
   stages {
     stage('first child')

{        ...      }
     stage('second child') {        ...      }

   }
}
```

philipp.abraham@innogames.com (JIRA)

unread,
Apr 3, 2019, 9:27:03 AM4/3/19
to jenkinsc...@googlegroups.com
Philipp Abraham edited a comment on New Feature JENKINS-43336
`env` ist is not available in ` options ` I think, but you could try getting the node name from the API:


```

stage('Parent') {
   options {
     lock("${currentBuild.getRawBuild().getExecutor().getOwner().getDisplayName()}")
   }
   stages {
     stage('first child')
{

{
       ...
     }
     stage('second child')
\ {
       ...
     }

   }
}
```

philipp.abraham@innogames.com (JIRA)

unread,
Apr 3, 2019, 9:29:03 AM4/3/19
to jenkinsc...@googlegroups.com
Philipp Abraham edited a comment on New Feature JENKINS-43336
` {{ env ` }} is not available in ` {{ options ` }} I think, but you could try getting the node name from the API:
{code:java}
```

stage('Parent') {
   options {
     lock("${currentBuild.getRawBuild().getExecutor().getOwner().getDisplayName()}")
   }
   stages {
     stage('first child')

{       
...     
}
     stage('second child') \ {       
...      }

  
}
}
``` }{code}

andrii@vozniuk.com (JIRA)

unread,
Apr 10, 2019, 5:20:03 AM4/10/19
to jenkinsc...@googlegroups.com

Hi, just wanted to add that we have the same problem where we need to lock multiple stages at once for atomicity (environment build and integration tests go together). Also, we need to parametrise the lock with the environment against which the build is done: it is ok to have parallel builds against different environments, but not against the same one.

As it looks, currently the multistage lock is available only in the options section which does not support environment parameters. Hence, it looks that we can not achieve what we need.

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:03 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Duplicate
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages