docker - 如何在 Docker 容器之外执行部分 Jenkins 管道阶段?
问题描述
我们有一个容器化的 Jenkins 管道,对于其中一个阶段,阶段的一部分,我们希望在容器上执行,一些在 Jenkins 主服务器上执行(在我们的例子中是 Windows) -
pipeline {
agent {
docker {
label "<node-name>"
image "<docker-image-path>"
}
}
stages {
stage('Testing') {
steps {
script {
//This below part will be executed on container
println "This below part will be executed on container"
sh '''pwd
hostname -i
'''
// Now want to execute below code on master which is Windows
println "Now want to execute below code on master which is Windows"
node('master') {
bat 'dir'
}
}
}
}
}
}
要在容器上执行的部分已成功执行,但要在 Windows Jenkins master 上执行的代码失败 -
Cannot run program "docker" (in directory "C:\Jenkins\workspace\TestDocker"): CreateProcess error=2, The system cannot find the file specified
编辑
当我在 Windows 机器上安装 docker 时,不会抛出上述错误,而是永远卡在那里。
你能帮我如何按需在节点或容器上执行代码吗?
解决方案
推荐阅读
- javascript - TypeScript `is` 类型谓词(用户定义的类型保护函数)来实现幂等对象类型
- ruby - DateTime 字段未正确更新
- sql - 有没有组合这两个 SQL 查询?
- coq - `induction n, m`和`induction n有什么区别?Coq中的感应m`?
- python - 有没有一种有效的方法来比较两个不同大小的数据帧?
- node.js - Firestore:然后触发两次?
- c# - 使用异步/等待 - C#
- python - python中是否有一个函数可以替换字符串中的字符,反之亦然?
- c++ - c++ 可变参数宏可以读取分布在多行的参数吗?
- ruby - 我在 Ruby on Rails 中使用关联时遇到问题