jenkins - 我可以在 Jenkins 中使用 Scripted Pipeline 指定节点吗?
问题描述
我注意到 Jenkins 管道文件 -- Jenkinsfile 有两种语法
- 声明式
- 脚本化的
我已经使声明性脚本工作以指定节点来运行我的任务。但是我不知道如何将我的脚本修改为脚本语法。
我的声明性脚本
pipeline {
agent none
stages {
stage('Build') {
agent { label 'my-label' }
steps {
echo 'Building..'
sh '''
'''
}
}
stage('Test') {
agent { label 'my-label' }
steps {
echo 'Testing..'
sh '''
'''
}
}
stage('Deploy') {
agent { label 'my-label' }
steps {
echo 'Deploying....'
sh '''
'''
}
}
}
}
我曾尝试以这种方式使用:
node('my-label') {
stage 'SCM'
git xxxx
stage 'Build'
sh ''' '''
}
但似乎詹金斯找不到我的节点来运行。
解决方案
这个简单的例子怎么样?
stage("one") {
node("linux") {
echo "One"
}
}
stage("two") {
node("linux") {
echo "two"
}
}
stage("three") {
node("linux") {
echo "three"
}
}
或者下面的答案,如果有多个具有相同标签的节点并且运行被另一个作业中断,则可以保证这些阶段在同一个节点上运行。上面的示例将在每个阶段后释放节点,下面的示例将保留所有三个阶段的节点。
node("linux") {
stage("one") {
echo "One"
}
stage("two") {
echo "two"
}
stage("three") {
echo "three"
}
}
推荐阅读
- serverless-framework - 如何将多个 serverless.yml 文件合并为单个 serverless.yml 文件?
- qt - 使用 sudo 权限的 Qt 复制文件
- java - 使用两个 for 循环简化计数(使用流)
- javascript - 带有条件的javascript过滤方法
- sql - 如何在 power bi URL 中添加过滤器?
- android - 在 Android 中旋转按钮
- regex - 正则表达式匹配至少 6 位数字,最多只有 3 位数字不同于 0
- nginx - 如何将 nginx.org 配置为渡槽服务器的代理服务器?
- collections - 在 Postman 中,不使用 Collection Runner 时如何定义 pm.iterationData()?
- go - 使用带模块的 Golang1.11 时 Protobuf 导入“找不到文件”