【发布时间】:2021-12-29 18:06:26
【问题描述】:
我在 Jenkins FreeStyle Job Type 中有一个选择参数。
选择变量 ${IP}:
192.168.1.33-prod
192.168.1.34-qa
192.168.1.35-stage
在可执行Shell脚本中,我想在将值分配给命令之前,删除所选选择参数中“-”之后的值。
执行的命令:
rsync --owner=ec2-user --group=ec2-user -O --no-p -arzh --exclude ".git/" --perms --chmod=a+rwx /tmp/some-value/ ec2-user@${IP}:/some-folder/
Linux 命令是:
echo ${IP} | cut -f1 -d"-"
结果应该是 结果:
192.168.1.33
执行前的最终命令应如下所示:
但是,当我尝试以下方式时,该值变为空:
rsync --owner=ec2-user --group=ec2-user -O --no-p -arzh --exclude ".git/" --perms --chmod=a+rwx $WORKSPACE/ ec2-user@192.168.1.33:/some-folder/
【问题讨论】:
-
只需使用groovy拆分值并提取IP:
${params.IP.split('-').first()} -
你在 jenkins 工作中在哪里执行 grovy 脚本? @NoamHelmer
-
看看Groovy Plugin,但你的 sh 分离命令也应该可以工作。你能进一步解释什么不起作用吗?
-
您的问题在
The Final Command before execution should look like:之后缺少一些文字。the value is coming empty when i try the below way:之后的输出看起来完全正确。