【问题标题】:Calling a job in a Multi Branch pipeline在多分支管道中调用作业
【发布时间】:2016-06-21 13:16:45
【问题描述】:

背景

我想在 Jenkins 中创建一个非常简单的流水线。例如:

  • 第 1 阶段:使用 maven 构建
  • 第 2 阶段:构建 docker 映像

在我的项目的根目录中,我有以下 Jenkinsfile:

stage 'build'
node {
    def branch = env.BRANCH_NAME
    build job: 'Maven job', parameters: [[$class: 'StringParameterValue', name: 'BRANCH_TO_BUILD', value: branch], [$class: 'StringParameterValue', name: 'MAJOR_VERSION_NUMBER', value: '1.0']]
}
stage 'Docker image'
node{
    echo 'TODO://Get jar file from previous job and build Docker image'
}

Maven Job 作业将创建一个 jar 文件,我想在下一阶段使用它来构建我的 docker 映像。

我使用外部作业来构建我的项目的原因是因为我正在使用 JFrog Artifactory,并且我希望我的所有依赖项都可以通过 Artfifactory 解决。

documentation for the Artifactory Jenkins plugin 声明:

The current plugin version does not include pipeline DSL for Maven and Gradle builds, but this will become available soon.

如果我直接使用 Maven 从 Groovy 脚本构建项目,它将无法解决来自 Artficatory 的依赖关系,这不是我想要的。

我安装了Copy Artifact 插件,我的Maven Job 在构建结束时归档了jar 文件。

问题

来自Jenkinsfile,如何从我刚刚调用的作业中访问归档的 jar 文件?

【问题讨论】:

    标签: java maven jenkins groovy jenkins-workflow


    【解决方案1】:

    您可以使用stash 选项:

    stash excludes: 'files_i_dont_want', includes: 'files_i_want', name: 'my_custom_name' unstash 'my_custom_name'

    示例: 存储一些文件:https://github.com/jenkins-infra/jenkins.io/blob/master/Jenkinsfile#L62 unstash 一些文件:https://github.com/lordofthejars/starwars/blob/master/Jenkinsfile#L44

    另一种选择是使用 Copy Artifacts 插件:

    step([$class: 'CopyArtifact', excludes: 'do_not_copy.jar', filter: 'copy_this.jar', fingerprintArtifacts: true, projectName: 'Maven Job', target: 'target_dir'])

    你试过了吗?

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多