jenkins - 在詹金斯奴隶之间复制文件在管道中
问题描述
我们的目标是用多个代理划分我们的管道。
我们有一个名为 slave1 的从站,它的唯一目的是在 git 上签出,并构建可执行文件。
最终,当 slave1 完成时,我们希望将它的输出传递给 slave2,它的唯一目的是测试 slave1 的可执行文件。
请注意,这里的想法不是拆分作业,而是在同一管道中实现文件。
Jenkinsfile
这是一个更有意义的示例:
pipeline
{
agent
{
label 'slave1'
}
stages
{
stage("Initialize & Build")
{
steps
{
script
{
println("Im starting the pipeline with slave1!")
// Builds Files
// ....
// Has many files that needs to pass to slave2
}
}
}
stage("Execute & Test")
{
agent
{
label 'slave2'
}
steps
{
script
{
println("Im in the new slave - slave2!")
// How does this slave get the files?
}
}
}
}
}
如何在代理之间传递这些文件?
我阅读了有关工件的信息,但似乎它的目标是从工作中返回对象,这不一定是需要的。
解决方案
如果您的两个代理都在 linux 服务器上,您可以简单地将代理 1 的构建输出 scp 到代理 2。此外,首先您需要在这 2 个代理之间建立无密码 SSH 连接。
这是一个例子。
pipeline
{
agent
{
label 'slave1'
}
stages
{
stage("Initialize & Build")
{
steps
{
script
{
println("Im starting the pipeline with slave1!")
// Builds Files
// ....
// option 1: copy files in the workspace of agent 2.
scp $WORKSPACE/build_output/* <user>@agent2:/home/<user>/workspace/<job_name>/
// option 2: copy files to any known location of agent 2
scp $WORKSPACE/build_output/* <user>@agent2:/<destination_path>
}
}
}
stage("Execute & Test")
{
agent
{
label 'slave2'
}
steps
{
script
{
println("Im in the new slave - slave2!")
//option 1
dir($WORKSPACE) {
// Test execution steps
}
// option 2
dir(<destination_path>) {
// Test execution steps
}
}
}
}
}
}
推荐阅读
- java - 如何仅显示视频文件夹?
- reactjs - 错误:在 CRA v2.1.7 和 craco v3.5.0 中,`fsevents` 不可用(此观察程序只能在 Darwin 上使用)
- c# - C# - 如何使用 FormUrlEncodedContent 更新 JSON 正文中的嵌套值?
- swiftui - 使用 ForEach 插入的 SwiftUI 视图未随动画更新
- reactjs - 从本地服务器获取反应显示不可能
- swift - 如何创建 Codable Struct 的实例?
- javascript - AngularJS 不使用 SignalR 更新 UI
- html - JSTL 表示类似文本
- python - 增量查找和修改数组中的重复值(Python)
- apache-flink - 如何在 pod 中运行 flink jar