我有一个 Jenkins 管道,其构建步骤有一个archiveArtifacts
命令。
构建步骤之后是单元测试、集成测试和部署。
在部署步骤中,我想使用其中一个工件。我以为我可以在构建步骤生成它的同一个地方找到它,但显然archiveArtifacts
已删除它们。
作为一种解决方法,我可以在存档之前复制该工件,但对我来说它看起来并不优雅。还有更好的办法吗?
据我了解,archiveArtifacts 更多的是用于在构建完成后保存工件以供某些人(或某人)使用。我建议考虑使用“stash”和“unstash”在阶段或节点之间传输文件。
你只要走...
stash include: 'globdescribingfiles', name: 'stashnameusedlatertounstash'
当你以后想取回那个神器时......
unstash 'stashnameusedlatertounstash'
并且隐藏的文件将被放入当前工作目录中。
这是 Jenkinsfile 文档中给出的示例(https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents):
pipeline {
agent none
stages {
stage('Build') {
agent any
steps {
checkout scm
sh 'make'
stash includes: '**/target/*.jar', name: 'app'
}
}
stage('Test on Linux') {
agent {
label 'linux'
}
steps {
unstash 'app'
sh 'make check'
}
post {
always {
junit '**/target/*.xml'
}
}
}
stage('Test on Windows') {
agent {
label 'windows'
}
steps {
unstash 'app'
bat 'make check'
}
post {
always {
junit '**/target/*.xml'
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)