根據這篇文章,我剛剛在我的 jenkins 服務器上設定了 docker build slaves來轉移靜態構建節點。
我遇到了一個小問題。我使用 bitbucket 和bcbsn來更新構建狀態。我不想在我所有的構建從站中安裝 go 并維護它,所以我考慮像這樣使用來自 bcbsn 的 docker 映像
docker run utrecht/bcbsn:2.0.4 -clientID ${clientID} -clientSecret ${clientSecret} -state FAILED -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}
我已經閱讀了這篇關于在 docker 中運行docker以及所有優缺點的文章,得出的結論是我不希望這樣。
因此,我希望它可以在主節點上運行,或者只在我為構建從站設定的 docker 主機上運行。這可能嗎?如果是這樣,該怎么做?
我自己的嘗試
stages {
stage ('Staging'){
steps {
withCredentials([usernamePassword(credentialsId: '6eab2fcc-7703-4d92-9e7d-120d66f771b3 ', usernameVariable: 'clientID', passwordVariable: 'clientSecret')]) {
docker.withServer('tcp://192.168.0.247:4243') {
docker.image('utrecht/bcbsn:2.0.4').withRun("-clientID ${clientID} -clientSecret ${clientSecret} -state INPROGRESS -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}") {
/* do nothing */
}
}
}
}
}
這導致
Method calls on objects not allowed outside "script" blocks.
我使用 bcbsn 的管道中的片段:
在我最初的構建步驟中:
stages {
stage ('Staging'){
steps {
withCredentials([usernamePassword(credentialsId: '00000000-0000-0000-0000-000000000000', usernameVariable: 'clientID', passwordVariable: 'clientSecret')]) {
sh "docker run utrecht/bcbsn:2.0.4 -clientID ${clientID} -clientSecret ${clientSecret} -state INPROGRESS -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}"
}
}
}
在我的帖子部分:
post {
//https://jenkins.io/doc/pipeline/tour/post/
changed {
script {
hasChanged = true
}
}
success {
script {
if(hasChanged){
echo '************** First success in a while! '
}
}
withCredentials([usernamePassword(credentialsId: '00000000-0000-0000-0000-000000000000', usernameVariable: 'clientID', passwordVariable: 'clientSecret')]) {
sh "docker run utrecht/bcbsn:2.0.4 -clientID ${clientID} -clientSecret ${clientSecret} -state SUCCESSFUL -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}"
}
}
failure {
script {
if(hasChanged){
echo '************** Build broke '
}
}
echo "Setting build status in Bitbucket"
withCredentials([usernamePassword(credentialsId: '00000000-0000-0000-0000-000000000000', usernameVariable: 'clientID', passwordVariable: 'clientSecret')]) {
sh "docker run utrecht/bcbsn:2.0.4 -clientID ${clientID} -clientSecret ${clientSecret} -state FAILED -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}"
}
}
}
uj5u.com熱心網友回復:
如果要使用與 Docker 類的 Jenkins Pipeline 插件互動的全域變數方法,則script在使用宣告性管道語法時需要將這些方法嵌套在塊內:
stage ('Staging'){
steps {
script {
withCredentials([usernamePassword(credentialsId: '6eab2fcc-7703-4d92-9e7d-120d66f771b3 ', usernameVariable: 'clientID', passwordVariable: 'clientSecret')]) {
docker.withServer('tcp://192.168.0.247:4243') {
docker.image('utrecht/bcbsn:2.0.4').withRun("-clientID ${clientID} -clientSecret ${clientSecret} -state INPROGRESS -commit ${env.GIT_COMMIT} -name ${buildName} -repoSlug talentindicator -owner talentinsights -url ${env.JOB_URL} -key ${buildName}") {
/* do nothing */
}
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489942.html
