Jenkins:从多分支流水线复制构件

5

我是Jenkins的新手,我在Bitbucket上有4个仓库,分别是A、B、C、D。 我需要获取A、B和C仓库,使用gradle build构建它们,生成war包。 现在我需要将这些war包复制到D\warsFolder文件夹中。 我创建了多分支流水线并生成了流水线语法,从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库中放置了Jenkinsfile并添加了上述脚本。

现在,我创建了一个名为Fetch_all的多分支流水线,在分支源中->单个存储库和分支->存储库URL中添加了http://.../A.git(其中包含Jenkinsfile)。到此为止,一切都正常,我能够获取资源并构建它们。

我创建了一个新的Freestyle作业,在源代码管理中->Git->存储库URL将是http://.../D.git。我正在尝试复制在 Fetch_all流水线中生成的war文件,但是在构建 ->从另一个项目复制工件中,项目名称不接受多分支流水线。它抛出错误如下:

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.

非常感谢您的帮助。

2个回答

5
最终成功了,当我提供pipeline_name/branchname即Fetch_all/%00时,它正常工作了。

3

花费了一些时间才找到正确的语法。 Coyartifact插件 的文档有点令人困惑,因为它提到了特殊字符的编码。实际上,空格不需要编码,但是斜杠必须编码。

复制工件的 Jenkinsfile 位于 'Other-folder/Multi branch Pipeline Test/',请将以下内容放入其中,以复制 'Folder/Multi branch Pipeline/feature%2Fallow-artifact-copy' 项目最后一个成功构建的工件

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接