在Jenkins Multibranch管道中配置cmake以构建

xu3bshqb  于 2023-05-16  发布在  Jenkins
关注(0)|答案(1)|浏览(208)

我很难配置cmake在声明式Jenkins多分支管道中工作,以构建和运行单元测试。
下面是Jenkins日志输出。

Obtained Jenkinsfile from ee03d9be78e0bf8585e6e122fcc03f6e13365cff
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /Users/mattwalsh/.jenkins/workspace/matt-wash-projects_main
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential mattwalsh-github-creds
Cloning the remote Git repository
Using shallow clone with depth 2
Cloning repository https://github.com/mysticrecords/out-of-tree-builds.git
 > git init /Users/mattwalsh/.jenkins/workspace/matt-wash-projects_main # timeout=10
Fetching upstream changes from https://github.com/mysticrecords/out-of-tree-builds.git
 > git --version # timeout=10
 > git --version # 'git version 2.30.1 (Apple Git-130)'
using GIT_ASKPASS to set credentials mattwalsh-github-creds
 > git fetch --tags --force --progress --depth=2 -- https://github.com/mysticrecords/out-of-tree-builds.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/mysticrecords/out-of-tree-builds.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision ee03d9be78e0bf8585e6e122fcc03f6e13365cff (main)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f ee03d9be78e0bf8585e6e122fcc03f6e13365cff # timeout=1
Commit message: "jenkinsfile"
 > git rev-list --no-walk ee03d9be78e0bf8585e6e122fcc03f6e13365cff # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Configure)
[Pipeline] dir
Running in /Users/mattwalsh/.jenkins/workspace/matt-wash-projects_main/build
[Pipeline] {
[Pipeline] cmake
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
Stage "Build" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test)
Stage "Test" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] archiveArtifacts
Archiving artifacts
[Pipeline] xunit
INFO: Processing CTest-Version 3.x (default)
INFO: [CTest-Version 3.x (default)] - No test report file(s) were found with the pattern 'build/*.xml' relative to '/Users/mattwalsh/.jenkins/workspace/matt-wash-projects_main' for the testing framework 'CTest-Version 3.x (default)'.
Did you enter a pattern relative to (and within) the workspace directory?
Did you generate the result report(s) for 'CTest-Version 3.x (default)'?"
INFO: Check 'Skipped Tests' threshold.
INFO: Check 'Failed Tests' threshold.
[Pipeline] deleteDir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: There is no Cmake installation selected. Please review the build step configuration and make sure the installation is configured on the Global Tool Configuration page.

GitHub has been notified of this commit’s build result

Finished: FAILURE

Jenkinsfile声明性管道。我已经在我的本地环境中测试了每个阶段的shell脚本命令,它们都能正常工作。

pipeline {
  agent any
  stages {
    stage('Configure') {
      steps {
        dir('build') {
          cmake(
            installation: 'InSearchPath'
          )
          sh 'cmake .'
        }
      }
    }
    stage('Build') {
      steps {
        dir('build') {
          sh 'cmake --build .'
        }
      }
    }  
    stage('Test') {
      steps {
        dir('build') {
          sh 'ctest -C checkin --output-junit unittest.xml'
        }
      }
    }
  }
  post {
    always {
      // Archive the CTest xml output
      archiveArtifacts (
        artifacts: 'build/*.xml',
        fingerprint: true
      )

      // Process the CTest xml output with the xUnit plugin
      xunit (
        testTimeMargin: '3000',
        thresholdMode: 1,
        thresholds: [
          skipped(failureThreshold: '0'),
          failed(failureThreshold: '0')
        ],
      tools: [CTest(
          pattern: 'build/*.xml',
          deleteOutputFiles: true,
          failIfNotNew: false,
          skipNoTestFiles: true,
          stopProcessingIfError: true
        )]
      )

      // Clear the source and build dirs before next run
      deleteDir()
    }
  }
}

我在jenkins中配置了cmake插件
cmake plugin configuration in jenkins
还有什么我可以尝试让这个工作吗?
我试图在内置节点上构建这个,如果这对它有影响?
我对使用Jenkins很陌生,因此非常感谢任何帮助。这一次真的把我卡住了。

9njqaruj

9njqaruj1#

根据Jenkins日志文件克隆的存储库没有build目录,这就是为什么dir('build')步骤在切换到该目录之前创建一个空目录。然后,您尝试在该空目录中调用cmake .,但失败了,因为该目录中没有CMakeLists.txt文件,并且您也没有提供额外的参数来将CMake指向源。
此外,CMake插件提供的cmakectestcpack步骤直接调用这些工具,不修改环境。因此,您不需要使用sh步骤再次运行cmake
下面的Jenkinsfile应该可以正常工作,假设您已经正确配置了名称为InSearchPath的CMake安装:

pipeline {
  agent any
  stages {
    stage('Configure') {
      steps {
        cmake arguments: '''
          -S projects
          -B build
         ''', installation: 'InSearchPath'
      }
    }
    stage('Build') {
      steps {
        cmake arguments: '--build build', installation: 'InSearchPath'
      }
    }  
    stage('Test') {
      steps {
        ctest arguments: '''
          --test-dir build
          --output-junit unittest.xml
        ''', installation: 'InSearchPath'
      }
    }
  }
  post {
    always {
      // Archive the CTest xml output
      archiveArtifacts (
        artifacts: '**/unittest.xml',
        fingerprint: true
      )

      // Process the CTest xml output with the xUnit plugin
      xunit (
        testTimeMargin: '3000',
        thresholdMode: 1,
        thresholds: [
          skipped(failureThreshold: '0'),
          failed(failureThreshold: '0')
        ],
        tools: [CTest(
          pattern: '**/unittest.xml',
          deleteOutputFiles: true,
          failIfNotNew: false,
          skipNoTestFiles: true,
          stopProcessingIfError: true
        )]
      )

      // Clear the source and build dirs before next run
      deleteDir()
    }
  }
}

我省略了CTest的-C checkin标志,因为我认为这不会起作用:-C用于指定生成的配置,但checkin不是有效的配置名称(应为ReleaseRelWithDebInfoMinSizeRelDebug)。如果你真的添加了一个名为checkin的配置,那就继续把它放回去,但是添加配置是一个糟糕的想法,应该避免。
最后一个提示:在下一次运行之前,使用deleteDir步骤结束管道。这是不可靠的,因为如果强制中止,管道可能会中止,并且不会正确清理。如果你每次都需要干净的构建,你应该在通过scm步骤从git中手动 checkout 代码之前,首先运行deleteDir

相关问题