【问题标题】:Jenkins job pipeline type clone only gdsl file without clone the whole git repositoryJenkins 作业管道类型仅克隆 gdsl 文件而不克隆整个 git 存储库
【发布时间】:2019-10-20 10:44:12
【问题描述】:

为了总结这个问题,我有一个名为 Repo_A 的 git 存储库。
Repo_A 包含:

Repo_A:
---> release-pipeline.gdsl
---> src/
---> pom.xml

release-pipeline.gdsl 内容:

node(params.node) {
    stage('Build Source Code') {
        sh 'pwd'
        sh 'ls -l'
        sh 'mvn clean compile package'
    }
}

stage的输出如下(Jenkins项目名称Repo_A_CI_Project):

Started by user MyUser
Obtained release-pipeline.gdsl from git git@github.com:Repo_A.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on myServer in /home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build Source Code)
[Pipeline] sh
+ pwd
/home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project
[Pipeline] sh
+ ls -l
total 0
[Pipeline] sh
+ mvn clean compile package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.735 s
[INFO] Finished at: 2019-10-20T09:26:34+00:00
[INFO] Final Memory: 25M/1963M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
ERROR: script returned exit code 1
Finished: FAILURE

这里的问题是 Jenkins Pipeline 不会克隆整个 Repo_A 存储库内容。它只获取 gdsl 文件release-pipeline.gdsl

工作是管道类型,我已经为这个项目设置了正确的配置,git repo 应该拉什么。

以前它可以正常工作并拉取整个 repo 并考虑 repo 根目录上的执行位置以开始执行阶段的命令。

从日志中可以看出,我使用ls -l 来查看内容,结果显示为0。

[Pipeline] sh
+ ls -l
total 0
[Pipeline]

我希望看到这样的情况

[Pipeline] sh
+ ls
release-pipeline.gdsl src/ pom.xml
[Pipeline]

在 Jenkins 日志中,我看到的唯一内容就是这条简单的消息。

org.jenkinsci.plugins.githubautostatus.GithubNotificationConfig log
INFO: Could not find commit sha - status will not be provided for this build

我正在使用这种方法,因为它很容易拉取 Jenkins 构建文件 (release-pipeline.gdsl) 以及 repo 的其他内容直接构建而无需额外步骤。

感谢您的帮助。

【问题讨论】:

    标签: git jenkins jenkins-pipeline


    【解决方案1】:

    您很可能在作业配置页面中选中了轻量级结帐复选框。

    如果选中,请尝试直接从 SCM 获取 Pipeline 脚本内容,而不执行完整的签出。

    只需清除复选框即可。

    编辑

    如果不使用options { skipDefaultCheckout() },上述方法在Declarative Pipelines 中可以自动签出阶段中的源代码。因此,对于这个涉及脚本化管道的问题,它并不适用。

    在 Scripted Pipelines 中,默认情况下,Jenkins 不一定会在您运行阶段的同一节点中签出存储库。在这种情况下,您需要在您的阶段调用步骤checkout scm(它使用在作业的管道部分配置的 SCM)并选中 Lightweight checkout 复选框以避免两次签出。

    此外,对于多行命令,您可以使用 ''' 调用 sh 步骤,而不是调用三次。

    node(params.node) {
        stage('Build Source Code') {
            checkout scm
            sh '''
                pwd'
                ls -l
                mvn clean compile package
            '''
        }
    }
    

    【讨论】:

    • 感谢您的帮助,我取消了轻量级结帐框,我从日志中看到它开始签出 git repo Repo_A。但即便如此/home/MyUser/jenkins_agent/workspace/Repo_A_CI_Project下仍然没有内容
    • @slh-ibm 糟糕,我完全错过了您使用的是脚本化管道这一事实。我已经用编辑部分更新了答案来解决这个问题。
    • 感谢@Dibakar 的更新,这很有帮助。我不知道为什么 StackOverFlow 要求我们避免使用 +1 或谢谢的 cmets。无论如何 +1000 给你,谢谢
    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    相关资源
    最近更新 更多