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:
parent
eea0c1f35e
commit
26e817ca29
@ -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 = [:]
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user