My Jenkinsfile pipeline currently looks like this:
...
stage('Testing') {
sh '$(git diff HEAD^ requirements.txt) > requirements_change.txt'
sh 'cat requirements_change.txt'
script {
some_variable = 'requirements_change.txt'
When I build the above pipeline in Jenkins, the line sh 'cat requirements_change.txt' outputs all of the git diffs of the requirements.txt file as expected.
Is it possible to turn all of these git diffs into one long string?
My intention is to assign this string to a variable that then gets passed on.
The issue with the code written above is that some_variable points to the path/file of requirements_change.txt, but what I need instead is the contents of the text file.
@mawinter69 is there a way to verify after the line above that some_variable is a string? Because I suspect it is not due to the error I get when passing along the varaible.
You are running into shell-quoting issues most probably.
The bl script needs adoption to read such complex input from file or stdin, not as an commandline arg.
If you insist on command line arg, (but remember that the lenght there is limited), bl could expect the diff to be passed as base64-encoded.
Thanks @bpedersen2 is it possible to turn the contents of the file into a string? If so I could assign it to a variable and pass a string along instead.
I’ve tried converting it into a string, but with no luck. Any suggestions on how I could do this?
It is not argparse that is failing, it is the shell parser that read it differently from what you expect. You would need to fully quote the contents of your string ( all shell meta chars, newlines and especially quote characters) , but that will soon become very tricky.