Skip to content

Commit

Permalink
Make stage locking more flexible (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kurzynski authored Jul 17, 2020
1 parent eea0c1f commit 26e817c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions vars/commonPipelineEnvironment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import groovy.json.JsonOutput

class commonPipelineEnvironment implements Serializable {

//Project identifier which might be used to distinguish resources which are available globally, e.g. for locking
def projectName

//stores version of the artifact which is build during pipeline run
def artifactVersion
def originalArtifactVersion
Expand Down Expand Up @@ -58,6 +61,8 @@ class commonPipelineEnvironment implements Serializable {

def reset() {

projectName = null

abapRepositoryNames = null

appContainerProperties = [:]
Expand Down
14 changes: 12 additions & 2 deletions vars/piperStageWrapper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void call(Map parameters = [:], body) {
.mixinStageConfig(script.commonPipelineEnvironment, stageName)
.mixin(parameters)
.addIfEmpty('stageName', stageName)
.addIfEmpty('lockingResourceGroup', script.commonPipelineEnvironment.projectName)
.dependingOn('stageName').mixin('ordinal')
.use()

Expand All @@ -46,8 +47,17 @@ void call(Map parameters = [:], body) {

private void stageLocking(Map config, Closure body) {
if (config.stageLocking) {
lock(resource: "${env.JOB_NAME}/${config.ordinal}", inversePrecedence: true) {
milestone config.ordinal
String resource = config.lockingResourceGroup?:env.JOB_NAME
if(config.lockingResource){
resource += "/${config.lockingResource}"
}
else if(config.ordinal){
resource += "/${config.ordinal}"
}
lock(resource: resource, inversePrecedence: true) {
if(config.ordinal) {
milestone config.ordinal
}
body()
}
} else {
Expand Down

0 comments on commit 26e817c

Please sign in to comment.