Cloudbees Jenkins Folders Plugin: Folder Name as Enviroment Variable

巧了我就是萌 提交于 2019-12-13 04:30:29

问题


Is the Folder Name available as an environment variable similar to JOB_NAME?

For a folder; JOB_NAME contains the full path including parent folders. I want the immediate parent folder as an environment variable.


回答1:


No such variable exists, but $(basename $(dirname $JOB_NAME)) would give you what you are asking for.




回答2:


Using the suggestion of $(basename $(dirname $JOB_NAME)) combined with the Environment Script Plugin, you should be able to set such an environment variable by selecting Generate environment variables from script and then providing the Script Content of:

echo FOLDER_NAME=$(basename $(dirname $JOB_NAME))



回答3:


I used:

FOLDER_NAME=${JOB_NAME%/*}
STAGE=${JOB_NAME##*/}

See http://www.tldp.org/LDP/abs/html/parameter-substitution.html



来源:https://stackoverflow.com/questions/18226368/cloudbees-jenkins-folders-plugin-folder-name-as-enviroment-variable

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