I am trying to run the below in jenkins and i get error any suggestions?
sh ''' sed -i \':a;N;$!ba;s/\\n/\\|\\#\\|/g\' ${concl} '''
Error - Why isnt the ${concl}
being repalced with filename inside the shell script?
+ sed -i ':a;N;$!ba;s/\n/\|\#\|/g'
sed: no input files
I would suggest running bash command in double quotes and escape $
and \
character. Consider following Jenkins pipeline exemplary script:
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Inital content of temp.txt file'
sh 'cat temp.txt'
sh "sed -i ':a;N;\$!ba;s/\\n/\\|\\#\\|/g' temp.txt"
echo 'Content of temt.txt file after running sed command...'
sh 'cat temp.txt'
}
}
}
}
The temp.txt
file I use in this example contains:
lorem ipsum
dolor sit amet
12 13 14
test|test
When I run it I get following console output:
Started by user admin
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] echo
Inital content of temp.txt file
[Pipeline] sh
[test-pipeline] Running shell script
+ cat temp.txt
lorem ipsum
dolor sit amet
12 13 14
test|test
[Pipeline] sh
[test-pipeline] Running shell script
+ sed -i :a;N;$!ba;s/\n/\|\#\|/g temp.txt
[Pipeline] echo
Content of temt.txt file after running sed command...
[Pipeline] sh
[test-pipeline] Running shell script
+ cat temp.txt
lorem ipsum|#|dolor sit amet|#||#|12 13 14|#||#|test|test|#|
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
After running the script temp.txt
file changes its contents to:
lorem ipsum|#|dolor sit amet|#||#|12 13 14|#||#|test|test|#|
Hope it helps.
This is not related to sed
but to string interpolation in Groovy. Variables (${variable}
) will not be replaced within single-quoted strings, only within double-quoted ones.
Thus, replace sh ''' ... '''
with sh """ ... """
or maybe just with sh ".."
as you have only one line or maybe with some Groovy/Java call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With