Jenkins does not show variables output in ECHO request in the groovy-pipeline

吃可爱长大的小学妹 提交于 2021-01-29 17:46:05

问题


just for example. I have this part of code in groovy-pipeline:

                echo "${GIT_BRANCH}"

                if ("${GIT_BRANCH}" == 'origin/mysuperbranch') {
                    echo 'Branch name is "${GIT_BRANCH}". We can continue'
                } else {
                    echo 'Branch name is "${GIT_BRANCH}". We can not continue'
                    isValid = false
                    return true
                }

And let's look on output:

[Pipeline] echo
origin/mysuperbranch
[Pipeline] echo
Branch name is "${GIT_BRANCH}". We can continue

Why in first output i can see what is in the variable ${GIT_BRANCH}, but in the next output, i see only ${GIT_BRANCH}. Can you help me please ?


回答1:


Refering to the String Interpolation you are writing the variable as string to the console. You have to remove the " from the variable and use them on the whole command to recognize variables.

echo "Branch name is ${GIT_BRANCH}. We can not continue"


来源:https://stackoverflow.com/questions/57319873/jenkins-does-not-show-variables-output-in-echo-request-in-the-groovy-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!