pipeline {
agent any
stages {
stage('Run Tests') {
parallel {
stage('1') {
steps {
echo "Running something here"
runOtherStepsOrStages()
}
}
stage('2') {
steps {
echo "run-tests.sh"
runOtherStepsOrStages()
}
}
stage('3') {
steps {
echo "run-tests.sh"
runOtherStepsOrStages()
}
}
}
}
}
}
def runOtherStepsOrStages(){
// Only one Stage will be able to aquare the lock, once aquiredother will skip, you can add another flag to make sure it's not executed again after the stage is completed
lock(resource: 'myLock', skipIfLocked: true) {
echo "Storing the steps/stages externally to reuse."
sleep 30
}
}
1条答案
按热度按时间hxzsmxv21#
你应该可以用不同的方法来实现它,比如Lockable Resource Plugin,它的思想是从每个初始阶段开始调用外部阶段执行,第一个调用的阶段将获得一个锁,防止其他阶段执行。