使用了gitlab管理pipeline,Jenkinsfile 中在出现克隆命令流水线执行会混乱

Jenkins_pipeline关闭默认检出

问题描述

在使用 Pipeline(流水线)过程中,如果使用了(Pipeline script from SCM)远程 Git 的 Jenkinsfile 方式,会出现代码检出 2 次的情况,如下图:
,当在 pipeline 中在次检出代码,就会检出 2 次,流水线执行会混乱

stage('克隆代码') {
            steps{
               git  credentialsId: "$gitlab_tokenid", url: "$git_url"
               sh 'ls -l'
            }
        }

问题解决

针对以上问题,在使用Pipeline script from SCM时只需要在 Jenkinsfile 文件中增加 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签出,则需要显式地包含它。

pipeline {
    agent {
       label "win7_x64"  //节点标签
    }
    options {
        skipDefaultCheckout true
        //忽略gitlab管理的jenkinsfile第一次检出
    }
}

效果:

默认不会在第一阶段检出代码

posted @ 2021-07-07 20:53  老头还我葵花宝典  阅读(212)  评论(0编辑  收藏  举报