我能否以某种方式从一个阶段复制数据以供在另一个阶段使用?
例如,我有一个阶段想要克隆我的存储库,而在另一个阶段运行 Kaniko,它将(在 dockerfile 上)所有数据复制到容器并构建它
如何做到这一点?因为
- 阶段是独立的,我无法在两个阶段通过相同的数据进行操作
- 在 Kaniko 上,我无法安装 GIT 以将其克隆到那里 提前致谢
代码示例:
pipeline {
agent none
stages {
stage('Clone repository') {
agent {
label 'builder'
}
steps {
sh 'git clone ssh://git@myrepo.com./repo.git'
sh 'cd repo'
}
}
stage('Build application') {
agent {
docker {
label 'builder'
image 'gcr.io/kaniko-project/executor:debug'
args '-u 0 --entrypoint=""'
}
}
steps {
sh '''#!/busybox/sh
/kaniko/executor -c `pwd` -f Dockerfile"
'''
}
}
}
}
附言在 dockerfile 上我使用诸如
ADD . /
最佳答案
你可以尝试使用stash :
stage('Clone repository') {
agent {
label 'builder'
}
steps {
sh 'git clone ssh://git@myrepo.com./repo.git'
script {
stash includes: 'repo/', name: 'myrepo'
}
}
}
stage('Build application') {
agent {
docker {
label 'builder'
image 'gcr.io/kaniko-project/executor:debug'
args '-u 0 --entrypoint=""'
}
}
steps {
script {
unstash 'myrepo'
}
sh '''#!/busybox/sh
/kaniko/executor -c `pwd` -f Dockerfile"
'''
}
关于jenkins - 在 Jenkins 管道的各个阶段之间传输数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67532771/