如何在docker容器开始运行之前执行步骤
我正在使用docker编写一个声明性jenkins文件。我需要做的是克隆一些repo,对这些repo做一些工作,然后运行docker容器来构建代码。我所看到的是,运行docker容器之前的步骤可以在一个代理上运行,而docker容器可以在另一个代理上运行。我认为正确的做法是在运行docker容器之前隐藏代码,但我不知道如何在docker容器运行之前将其解压缩到正确的代理上(请参阅下面的“docker测试”阶段)。我的文件如下所示:如何在docker容器开始运行之前执行步骤,docker,jenkins,jenkins-pipeline,devops,docker-machine,Docker,Jenkins,Jenkins Pipeline,Devops,Docker Machine,我正在使用docker编写一个声明性jenkins文件。我需要做的是克隆一些repo,对这些repo做一些工作,然后运行docker容器来构建代码。我所看到的是,运行docker容器之前的步骤可以在一个代理上运行,而docker容器可以在另一个代理上运行。我认为正确的做法是在运行docker容器之前隐藏代码,但我不知道如何在docker容器运行之前将其解压缩到正确的代理上(请参阅下面的“docker测试”阶段)。我的文件如下所示: pipeline { agent { label 'my
pipeline {
agent { label 'my_docker_jenkins_agent' }
options {
timestamps()
}
stages {
stage('git') {
steps {
<clone repos here>
}
}
stage('do some post clone processing to the files') {
steps {
<do some post processing on the cloned files here>
}
}
post {
success {
/* tar up the source code for use in the docker container */
stash includes: 'foo/', name: foo-${env.BUILD_ID}
}
}
stage('docker test') {
/* how do I unstash the code onto the same agent the docker container will
* run on prior to the docker container starting here?
*/
agent {
docker {
label 'my_docker_jenkins_agent'
image 'docker_registry/test/f32-bld:0.1'
registryUrl 'https://my_internal_registry.foo.com'
registryCredentialsId '<credentials id not shown>'
}
}
steps {
<issue the make command on the unstashed code here>
}
}
}
}
管道{
代理{标记“我的码头工人”{jenkins}
选择权{
时间戳()
}
舞台{
阶段('git'){
台阶{
}
}
阶段('对文件进行克隆后处理'){
台阶{
}
}
职位{
成功{
/*在docker容器中使用源代码*/
隐藏内容包括:“foo/”,名称:foo-${env.BUILD_ID}
}
}
阶段(“docker测试”){
/*如何将代码解压缩到docker容器将使用的同一代理上
*在docker容器从这里开始之前运行?
*/
代理人{
码头工人{
贴上“我的码头工人、詹金斯、代理人”的标签
图像“docker_注册表/测试/f32 bld:0.1”
注册URL'https://my_internal_registry.foo.com'
注册表凭证ID“”
}
}
台阶{
}
}
}
}