Closed oldunclez closed 2 months ago
if using the following code , agent { label 'YTLdhost' }
works., but lock(resource: "${env.project_branch}")
not work , I.E. all the builds will be queued even the value of variable project_branch is different
pipeline {
environment {
gitlabBranch = "${env.gitlabBranch ?: env.branch}"
gitlabSourceRepoSshUrl = "${env.gitlabSourceRepoSshUrl ?: env.gurl}"
project = "${gitlabSourceRepoName ? gitlabSourceRepoName : (gitlabSourceRepoSshUrl.tokenize('/').last().replace('.git', ''))}"
project_branch = "${project}_${gitlabBranch}"
}
agent { label 'ubt' }
options {
lock(resource: "${env.project_branch}")
}
stages {
stage('stage1') {
steps {
script {
sleep 20
}
}
}
stage('stage2') {
agent { label 'YTLdhost' }
steps {
sh '''
#!/bin/bash
set +x
hostname
'''
}
}
}
}
According to
I use node("YTLdhost")
instead of agent { label 'YTLdhost' }
in stage2 , it works
pipeline {
environment {
gitlabBranch = "${env.gitlabBranch ?: env.branch}"
gitlabSourceRepoSshUrl = "${env.gitlabSourceRepoSshUrl ?: env.gurl}"
project = "${gitlabSourceRepoName ? gitlabSourceRepoName : (gitlabSourceRepoSshUrl.tokenize('/').last().replace('.git', ''))}"
project_branch = "${project}_${gitlabBranch}"
}
agent { label 'ubt' }
stages {
stage('refresh') {
steps {
lock(resource: "${env.project_branch}") {
script {
stage('stage1')
sh '''
sleep 20
'''
stage('stage2') {
node("YTLdhost") {
sh '''
#!/bin/bash
set +x
hostname
sleep 30
'''
}
}
}
}
}
}
}
}
I have a jenkins pipeline job which is trigger by the gitlab webhook. My goal is to :
The code is as following , but
agent { label 'YTLdhost' }
in stage2 does not work, it is excuted onagent { label 'ubt' }
, why ?Thank you