gpt4 book ai didi

jenkins - 在多个阶段之间重用 Jenkins 中的代理(docker 容器)

转载 作者:行者123 更新时间:2023-12-04 14:08:43 25 4
gpt4 key购买 nike

我有一个具有多个阶段的管道,我想在“n”个阶段之间重用一个 docker 容器,而不是所有阶段:

pipeline {
agent none

stages {
stage('Install deps') {
agent {
docker { image 'node:10-alpine' }
}

steps {
sh 'npm install'
}
}

stage('Build, test, lint, etc') {
agent {
docker { image 'node:10-alpine' }
}

parallel {
stage('Build') {
agent {
docker { image 'node:10-alpine' }
}

// This fails because it runs in a new container, and the node_modules created during the first installation are gone at this point
// How do I reuse the same container created in the install dep step?
steps {
sh 'npm run build'
}
}

stage('Test') {
agent {
docker { image 'node:10-alpine' }
}

steps {
sh 'npm run test'
}
}
}
}


// Later on, there is a deployment stage which MUST deploy using a specific node,
// which is why "agent: none" is used in the first place

}
}

最佳答案

您可以使用 scripted pipelines ,您可以在其中放置多个 stage走进 docker步骤,例如

node {
checkout scm
docker.image('node:10-alpine').inside {
stage('Build') {
sh 'npm run build'
}
stage('Test') {
sh 'npm run test'
}
}
}

(代码未经测试)

关于jenkins - 在多个阶段之间重用 Jenkins 中的代理(docker 容器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com