当前位置:网站首页>Jenkins Pipeline 对Job参数的处理
Jenkins Pipeline 对Job参数的处理
2022-06-28 18:42:00 【51CTO】
文章目录
- `1.1.脚本内容`
- `1.2.执行结果`
- `2.1.脚本`
- `2.2.执行结果`
一、判断参数的值是否为空
Job使用参数化构建,配置参数DOCKER_HOST和DB_HOST,现在需在groovy脚本中判断它们的值是否为空
1.1.脚本内容
解释:
1.2.执行结果

二、当参数的值是好几个IP地址,该如何提取呢?

2.1.脚本
解释:
2.2.执行结果

三、把Job参数写入到/etc/ansible/hosts文件

脚本
#
!
groovy
def
filePath
=
"/etc/ansible/hosts"
def
backupPath
=
"/etc/ansible/host_bak"
def
logTime
=
new
Date().
format(
'yyyyMMddHHmmss')
//提取当前时间戳
if(
!
fileExists(
backupPath)) {
sh
"mkdir ${
backupPath
}"
}
if(
fileExists(
filePath)) {
sh
"mv ${
filePath
} ${
backupPath
}/hosts_bak_${
logTime
}"
//执行Shell命令
}
outFile
=
new
File(
filePath)
//把文件转成一个File类
def
dockerIpList
=
this.
DOCKER_HOST.
split(
",")
//以逗号进行分割,并存入列表中
outFile.
append(
'['
+
'DOCKER_HOST'
+
']\n')
//如果文件不存在,会创建
for (
ip
in
dockerIpList) {
outFile.
append(
ip
+
'\n')
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
执行效果

边栏推荐
- 向上转型和向下转型
- Business layer modification - reverse modification based on the existing framework
- 数字化转型的1个目标,3大领域,6大因素和9个环节
- Yixin Huachen: real estate enterprises want to grasp the opportunity of the times for digital transformation
- Summary of the use of qobjectcleanuphandler in QT
- Taishan Office Technology Lecture: word strange font height
- 180.1.连续登录N天(数据库)
- Shell 未知汇总1
- 泰山OFFICE技术讲座:WORD奇怪的字体高度
- leetcode 1647. Minimum deletions to make character frequencies unique
猜你喜欢

应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)

Yixin Huachen: real estate enterprises want to grasp the opportunity of the times for digital transformation

Opengauss kernel: analysis of SQL parsing process

带你手把手实现grafana双轴图

ONEFLOW source code parsing: automatic inference of operator signature

C# 41. Int to string

sql计算每日新增用户、及留存率指标

基于管线的混合渲染

Render function parsing

About Statistical Distributions
随机推荐
Oom out of memory memory overflow
数字化转型的1个目标,3大领域,6大因素和9个环节
C# 41. Int to string
ONEFLOW source code parsing: automatic inference of operator signature
180.1. Log in continuously for n days (database)
render函数解析
Brief introduction to mongodb working principle of mongodb series
618 activity season - the arrival of special discounts for hundreds of low code platforms
ANR Application Not Responding
找出连续7天登陆,连续30天登陆的用户
Render function parsing
Win 10创建一个gin框架的项目
use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue
泰山OFFICE技术讲座:WORD奇怪的字体高度
pd.cut 区间参数设定之前后区别
Opengauss kernel: analysis of SQL parsing process
Mybayis之核心主件分析
安装nodejs环境
使用.NetCore自带的后台作业,出入队简单模拟生产者消费者处理请求响应的数据
Differences and relations among rxjs map, mergemap and switchmap