【问题标题】:Jenkins : Copy artifacts from Multibranch pipelineJenkins:从多分支管道复制工件
【发布时间】:2017-04-03 13:18:53
【问题描述】:

我是 Jenkins 的新手,我在 Bitbucket 中有 4 个 repo,比如 A、B、C、D。 我必须获取 A、B 和 C 存储库,使用 gradle build 构建它们,这将产生战争。 现在我必须在 D\warsFolder 中复制那些战争 我已经创建了 Multibranch 管道并生成了从 git 获取 A、B 和 C 并构建它们的管道语法。好像是这样的

    node {
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'A']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'id', url: 'http://.../A.git']]])
    dir('A') {
        bat 'gradle build -i --info --stacktrace --debug'
    }
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'B']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'id', url: 'http://.../B.git']]])
    dir('B') {
        bat 'gradle build -i --info --stacktrace --debug'
    }
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'C']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'id', url: 'http://.../C.git']]])
    dir('C') {
        bat 'gradle build -i --info --stacktrace --debug'
    }

    }

将上述脚本添加到我放在 A repo 中的 Jenkinsfile 中。

现在我创建了一个多分支管道 Fetch_all 并在分支源 -> 单个存储库和分支 -> 存储库 URL 中添加了 http://.../A.git(其中包含 Jenkinsfile)。 到目前为止一切正常,我可以获取源代码并构建它们。

我创建了 Freestyle 的新工作,在 Source Code Management -> Git -> Repository URL 将是 http://.../D.git。 我正在尝试复制 Fetch_all 管道中生成的战争,但在 Build -> Copy artifacts from another project 项目名称不接受 Multibranch 管道。它会抛出类似

的错误
ERROR: Unable to find project for artifact copy: 
This may be due to incorrect project name or permission settings; see help for project name in job configuration.

感谢任何帮助。

【问题讨论】:

    标签: jenkins jenkins-plugins jenkins-pipeline


    【解决方案1】:

    终于明白了,当我给出 pipeline_name/branchname 即 Fetch_all/%00 时,它工作正常。

    【讨论】:

      【解决方案2】:

      花了一些时间才找到正确的语法。 Coyartifact Plugin 的文档有点混乱,因为它提到了 encoding of special characters。实际上空格不必编码,但斜线必须编码。

      复制工件的Jenkinsfile位于'Other-folder/Multi branch Pipeline Test/',放入此内容以复制'Folder/Multi branch Pipeline/feature%2Fallow-artifact的上次成功构建的工件-复制'项目

      copyArtifacts(
          projectName: 'Folder/Multi branch Pipeline/feature%2Fallow-artifact-copy',// the name of project, as you find it from the root of jenkins
          selector: lastSuccessful(),             // selector to select the build to copy from. If not specified, latest stable build is used.
          filter: 'projects/Output/myzip.zip',    // ant-expression to filter artifacts to copy, Attention! Filter is case sensitive
          target: 'sources/deploy/',              // target directory to copy to, intermediate folders will be created
          flatten: true,                          // ignore directory structures of artifacts, Artifact will be placed at 'sources/deploy/myzip.zip'. Is the option false, you find it at 'projects/Outpu/myzip.py'
          optional: false,                        // do not fail the step even if no appropriate build is found.
          fingerprintArtifacts: true,             // fingerprint artifacts to track builds using those artifacts
      )
      

      并且不要忘记在要从中获取工件的项目中允许工件复制。将此添加到 'Folder/Multi branch Pipeline/feature%2Fallow-artifact-copy' 的 Jenkinsfile 中。使用绝对路径,以避免在移动某些项目时出现问题。

      options {
           disableConcurrentBuilds()
           timeout(time: 30, unit: 'MINUTES')
           copyArtifactPermission('/Other-folder/Multi branch Pipeline Test/*, /second Folder/*') // allow all the projects or branches of 'Other-folder/Multi branch Pipeline Test' and 'second Folder' to copy artifacts of this job
      } // end of options
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-20
        相关资源
        最近更新 更多