[英]Run Jenkins pipeline on local information if SCM is not accessible
我開發了一個由 SCM 的管道腳本定義的管道作業。 我使用 Git 作為單片機。 大多數情況下,Git 服務器是可以訪問的,沒有問題,但有時 git 服務器由於網絡問題等原因不可用。
在這種情況下,作業失敗。 Jenkins 引發以下異常:'''hudson.plugins.git.GitException:命令“git fetch --tags --progress --prune -- origin +refs/tags/...:refs/remotes/origin/.. ." 返回狀態碼 128:stdout:stderr:致命:無法訪問 '...':無法連接到代理端口 8080:連接超時'''
在這種情況下,我想管理這個異常,因為在之前的作業執行期間,我已經從 SCM 獲取了管道腳本。 在我看來,我們可以使用前面已經從 git 服務器下載的代碼。
管理這種異常以利用本地信息的方法嗎?
下面是我的管道腳本
pipeline {
agent { node 'master' }
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(daysToKeepStr: '60'))
skipDefaultCheckout()
}
stages {
stage("Checkout ft4cs-engine for subsystem report generation") {
steps {
timestamps {
script {
echo "Checkout repository"
dir('repository') {
try {
checkout([
$class: 'GitSCM',
branches: [[name: "${REPO_BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'LocalBranch', localBranch: '**'],
[$class: 'CleanBeforeCheckout']
],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'gitrepo', url: '<url gitlab>']]
])
}
catch (Exception e) {
echo "Catching exception during the checkout step : $e";
}
} // end of dir
} // end of script
} // end of timestamps
} // end of steps
} // end of stage
...
} // end of stages
} // end of pipeline
此致
我認為您嘗試如下:
runCheckOut=true
catch
更改runCheckOut=false
catch
中加載 Jenkinsfile
def runCheckout=true
pipeline {
agent { node 'master' }
options {
timestamps()
disableConcurrentBuilds()
buildDiscarder(logRotator(daysToKeepStr: '60'))
skipDefaultCheckout()
}
stages {
stage("Checkout") {
when {
expression {runCheckout}
}
steps {
script {
echo "Checkout repository"
dir('repository') {
try {
checkout([
$class: 'GitSCM',
branches: [[name: "${REPO_BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'LocalBranch', localBranch: '**'],
[$class: 'CleanBeforeCheckout']
],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'gitrepo', url: '<url gitlab>']]
])
}
catch (Exception e) {
echo "Catching exception during the checkout step : $e";
sh 'cp <path to your Jenkinsfile> <path to your Jenkinsfile>.groovy'
sh 'sed ...' // change runCheckout=true to runCheckout=false
load '<path to your Jenkinsfile>.groovy' // load new Jenkinsfile which will run all stages
}
} // end of dir
} // end of script
} // end of steps
} // end of stage
...
} // end of stages
} // end of pipeline
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.