1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Make stage locking more flexible (#1811)

This commit is contained in:
Daniel Kurzynski 2020-07-17 14:27:21 +02:00 committed by GitHub
parent eea0c1f35e
commit 26e817ca29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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
@ -58,6 +61,8 @@ class commonPipelineEnvironment implements Serializable {
def reset() {
projectName = null
abapRepositoryNames = null
appContainerProperties = [:]

View File

@ -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()
@ -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 {