天天看點

Jenkins_pipeline關閉預設檢出Jenkins_pipeline關閉預設檢出

Jenkins_pipeline關閉預設檢出

問題描述

在使用 Pipeline(流水線)過程中,如果使用了(Pipeline script from SCM)遠端 Git 的 Jenkinsfile 方式,會出現代碼檢出 2 次的情況,如下圖:

Jenkins_pipeline關閉預設檢出Jenkins_pipeline關閉預設檢出

,當在 pipeline 中在次檢出代碼,就會檢出 2 次,拉低整體速度

stage('克隆代碼') {
            steps{
                checkout([$class: 'GitSCM', 
                    branches: [[name: '${REF}']], 
                    extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'magicactiviti']], 
                    userRemoteConfigs: [[url: 'ssh://[email protected]:2223/lab/activiti_cn.git']]])
                sh 'ls -l'
            }
        }
           

問題解決

針對以上問題,在使用Pipeline script from SCM時隻需要更新到 Jenkinsfile 即可,是以增加 在 pipeline 檔案中增加 options 即可,具體實作如下:

官方插件介紹:

The skipDefaultCheckout option disables the standard, automatic checkout scm before the first stage. If specified and SCM checkout is desired, it will need to be explicitly included.
skipDefaultCheckout選項在第一階段之前禁用标準的自動簽出配置管理。如果指定并且需要SCM簽出,則需要顯式地包含它。
options {
    skipDefaultCheckout true
}
           

效果:

預設不會在第一階段檢出代碼

Jenkins_pipeline關閉預設檢出Jenkins_pipeline關閉預設檢出

繼續閱讀