OMG how hard can this be.... Trying to rename a file on disk.
stage('upload binaries')
{
steps
{
dir ("firmware")
{
script {
version = readFile("app/source/version.txt")
}
script {
newfilename = "app/build-app/app${version}.bin"
}
echo "hello....!"
echo "$version"
echo "$newfilename"
sh "mv app/build-app/app.bin app/build-app/app$version.bin"
upload_bin_file($newfilename)
}
}
}
Outputs this
Running in /var/jenkins_home/workspace/y_feature_upload-labelled-binary/firmware
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] readFile
[Pipeline] }
[Pipeline] // script
[Pipeline] script
[Pipeline] {
[Pipeline] }
[Pipeline] // script
[Pipeline] echo
hello....!
[Pipeline] echo
v1.0.51
[Pipeline] echo
app/build-app/appv1.0.51
.bin
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
WhatEVER I try, it never appends the ".bin" part.
- Tried single/double qoutes
- Tried $var and ${var}
- Tried $env.var and ${env.var}
- Tried escapning the 'dot' like app${version}.bin
Read the page on variables https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
Still no clue how to achieve this utmost trivial task.
Help? :)
CodePudding user response:
The value of the $version is coming from a file, so I believe this variable has a newline character.
Try to remove it.
testvar=`$testVar | tr -d '\n`