I need to pass the version number dynamically for sonar projects from jenkins pipeline. For that i have the version.txt file in the directory. I have declared that directory as variable in the script. Here is my script for declaring variable
script {
def myfile = readFile('C:/Jenkins/workspace/Int-Build-Start-Devenv/Src/version.txt')
echo "${myfile}"
}
in the above code it is printing the variable in console output but when i use this in sonar.projectVersion="${myfile}"
it is showing the version as version myfile in sonarqube server.
How to print that variable that I read my version.txt file into the sonar.projectVersion.
Please help me with this.
CodePudding user response:
myfile
is a normal variable and there is no reason you can't just use it like a normal variable. You have to wrap it in ${}
when echoing it as a string since it is a requirement when handling strings. But by what I get from your example, you should be able to simply use:
sonar.projectVersion=myfile
and expect it to work.
CodePudding user response:
Your bat command should be like "...${myfile}"
if it is a single line command or
"""...
...${myfile}"""
for a multiline command. Change single quotes with double quotes.