Jenkins管道:没有结帐代码

时间:2017-03-09 04:08:01

标签: jenkins jenkins-pipeline

我遇到了奇怪的行为,今天我第一次尝试使用Jenkins Pipeline并尝试使用作业内实际管道区域中提供的示例运行一个简单的管道。

    node {
       def mvnHome
       stage('Preparation') { // for display purposes
          // Get some code from a GitHub repository
          git 'https://github.com/jglick/simple-maven-project-with-tests.git'
          // Get the Maven tool.
          // ** NOTE: This 'M3' Maven tool must be configured
          // **       in the global configuration.           
          mvnHome = tool 'M3'
       }
       stage('Build') {
          // Run the maven build
          sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
       }
       stage('Results') {
          junit '**/target/surefire-reports/TEST-*.xml'
          archive 'target/*.jar'
       }
    }

奇怪的是:当我运行该作业时,它正确地运行准备阶段,然后转到构建并且失败说没有要执行的pom.xml,但查看所有那些的执行日志'没有提到git操作发生了。我查看了job文件夹,并且我试图在那里克隆的git存储库也没什么。

    [Pipeline] node
    Running on master in /Users/user/.jenkins/workspace/Test-Pipeline
    [Pipeline] {
    [Pipeline] stage
    [Pipeline] { (Preparation)
    [Pipeline] tool
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] stage
    [Pipeline] { (Build)
    [Pipeline] sh
    [Test-Pipeline] Running shell script
    + /opt/software/apache-maven-3.3.9/bin/mvn -Dmaven.test.failure.ignore                                 clean package
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.057 s
    [INFO] Finished at: 2017-03-08T22:54:41-05:00
    [INFO] Final Memory: 7M/309M
    [INFO] ------------------------------------------------------------------------
    [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/user/.jenkins/workspace/Test-Pipeline). 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

我尝试添加url属性,但也没有工作。根据配置Pipeline本身应该包含git,所以我猜测我在这里做错了什么。

我的配置: Jenkins 2.32.3和Pipeline 2.5

任何建议都表示赞赏。

2 个答案:

答案 0 :(得分:1)

结帐时使用了哪些凭据?如果在构建作业定义中选择Lightweight checkout选项,则Jenkins将仅从SCM恢复管道脚本文件,而不是检出完整的存储库。

enter image description here

通过舞台结账时,您可能需要凭据,可以在git调用中指定:

  stage ("Checkout") {
    git branch: '<branch>',
      credentialsId: '<creds-guid>',
      url: '<repo-url>'
  }

凭据ID应与Jenkins凭据存储中相应凭据的ID相匹配。 enter image description here

没有问过,但我还建议您使用withMaven步骤括起maven命令:

  stage ("Build") {
    withMaven(
        globalMavenSettingsConfig: '<config>',
        jdk: '<JDK>',
        maven: 'M3') {

        sh 'mvn <command>'
    }
  }

答案 1 :(得分:0)

使用Snippet Generator生成脚本: snippetGenerator

在管道脚本中使用生成的代码段: enter image description here