'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.
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:
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 | 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. Please let me know what I am missing. Thanks
Solution 1:[1]
I've found this working solution for my purposes. Simply use double quotes around the entire command, and escape only the $
in awk
sh "docker images -a | grep myimagename | awk '{print \$3}' | xargs docker rmi -f"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SegFault |