Jenkins作业管道类型仅克隆gdsl文件而不克隆整个git存储库

时间:2019-10-20 10:44:12

标签: git jenkins jenkins-pipeline

为解决问题,我有一个名为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'
    }
}

该阶段的输出如下(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应该将其拉出。

以前,它可以正常工作,并拉出整个存储库,并考虑执行位置在存储库根目录上,以开始执行阶段的命令。

从日志中可以看到,我使用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)和回购的其他内容很简单,无需额外步骤即可直接构建。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

enter image description here

  

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

只需清除复选框,您就应该可以了。

修改

如果未使用options { skipDefaultCheckout() },则上述方法可在声明式管道中自动在阶段中检出源代码。因此,对于涉及脚本管道的这个问题,它没有什么用。

在脚本化管道中,默认情况下,Jenkins不一定会在运行阶段的同一节点中检出存储库。在这种情况下,您需要在阶段中调用步骤checkout scm(使用在作业的“管道”部分中配置的SCM),并保留轻型结帐复选框,以避免两次结帐

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

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