简体   繁体   English

在詹金斯管道中转义单引号 awk 命令

[英]escape single quote awk command in jenkins pipeline

I get error "awk: fatal: cannot open file `print' for reading (No such file or directory)" when executing this command in jenkins pipeline.在詹金斯管道中执行此命令时,我收到错误“awk:致命:无法打开文件'print'进行读取(没有这样的文件或目录)”。

sh """ssh -o StrictHostKeyChecking=no -l jenkins jmeter-host1.com 'awk -F "|" '\''NR > 1{ print "SADD", "OFFICE_STORE", "\""\$0"\"" }'\'' /tmp/office_store.csv | redis-cli -h jmeter-host1.com -p 6379 --pipe'"""

The command below works fine when I enter in command line.当我在命令行中输入时,下面的命令可以正常工作。

awk -F "|" 'NR > 1{ print "SADD", "OFFICE_STORE", "\""$0"\"" }' /tmp/office_store.csv | redis-cli -h jmeter-host1.com -p 6379 --pipe

Here is result console log on jenkins:这是 jenkins 上的结果控制台日志:

ssh -o StrictHostKeyChecking=no -l jenkins jmeter-host1.com awk -F "|" ssh -o StrictHostKeyChecking=no -l jenkins jmeter-host1.com awk -F "|" NR print SADD, OFFICE_STORE, /var/lib/jenkins/workspace/Sandbox/Load_Test@tmp/durable-29e557f3/script.sh } /tmp/office_store.csv | NR 打印 SADD、OFFICE_STORE、/var/lib/jenkins/workspace/Sandbox/Load_Test@tmp/durable-29e557f3/script.sh } /tmp/office_store.csv | redis-cli -h jmeter-host1.com -p 6379 --pipe redis-cli -h jmeter-host1.com -p 6379 --pipe

I used ''\' to escape single quote at NR command, but in result console log, I see this single quote did not display on above command.我在 NR 命令中使用''\'转义单引号,但在结果控制台日志中,我看到此单引号未显示在上述命令中。 Please let me know what I am missing.请让我知道我错过了什么。 Thanks谢谢

I've found this working solution for my purposes.我已经为我的目的找到了这个可行的解决方案。 Simply use double quotes around the entire command, and escape only the $ in awk只需在整个命令周围使用双引号,并且只转义awk中的$

sh "docker images -a | grep myimagename | awk '{print \$3}' | xargs docker rmi -f"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM