通过声明式 Jenkinsfile,您可以使用以下管道:
pipeline {
agent any
stages {
stage ('push artifact') {
steps {
sh 'mkdir archive'
sh 'echo test > archive/test.txt'
zip zipFile: 'test.zip', archive: false, dir: 'archive'
archiveArtifacts artifacts: 'test.zip', fingerprint: true
}
}
stage('pull artifact') {
steps {
copyArtifacts filter: 'test.zip', fingerprintArtifacts: true, projectName: env.JOB_NAME, selector: specific(env.BUILD_NUMBER)
unzip zipFile: 'test.zip', dir: './archive_new'
sh 'cat archive_new/test.txt'
}
}
}
}
在 CopyArtifact 版本 1.39 之前,您必须将第二阶段替换为以下内容(感谢 @Yeroc):
stage('pull artifact') {
steps {
step([ $class: 'CopyArtifact',
filter: 'test.zip',
fingerprintArtifacts: true,
projectName: '${JOB_NAME}',
selector: [$class: 'SpecificBuildSelector', buildNumber: '${BUILD_NUMBER}']
])
unzip zipFile: 'test.zip', dir: './archive_new'
sh 'cat archive_new/test.txt'
}
}
With CopyArtifact
,我使用“${JOB_NAME}”作为项目名称,这是当前正在运行的项目。
使用的默认选择器CopyArtifact
使用最后一个成功的项目构建号,而不是当前的构建号(因为它尚未成功或尚未成功)。和SpecificBuildSelector
您可以选择“${BUILD_NUMBER}”,其中包含当前正在运行的项目版本号。
该管道适用于并行阶段,并且可以管理巨大的文件(我使用的是 300Mb 文件,它不适用于 stash/unstash)
如果您拥有所有需要的插件,该管道可以与我的 Jenkins 2.74 完美配合