英文:
How can i display the Job name of a Jenkins freestyle Job?
问题
I want to be able to get the name of the running job in Jenkins in PowerShell. I want to get the value and concatenate it to a string. For example, if the job name is TestJob and I get the correct value, I want to be able to create something like
"c:\myjobs\<thejobnamevalue>\dev\app.sln"
I have tried the following in the batch command:
WRITE-OUTPUT ${env.JOB_NAME}
WRITE-OUTPUT ${JOB_NAME}
But none prints out the job name, it just prints echo ${env.JOB_NAME}
or echo ${JOB_NAME}
.
英文:
I want to be able to get the name of the running job in Jenkins inPowershell. I want to get the value and concatenate it to a string for example if the Job name is TestJob and I get the correct value I want to be able to create something like
"c:\myjobs\<thejobnamevalue>\dev\app.sln"
I have tried the following in the batch command
WRITE-OUTPUT ${env.JOB_NAME}
WRITE-OUTPUT ${JOB_NAME}
But none prints out the job name, it just prints echo ${env.JOB_NAME} or echo ${JOB_NAME}
答案1
得分: 0
JOB_NAME
是保存作业名称的正确变量,因此我认为问题出在你尝试引用它的方式上。
如果你是在“执行 Windows 批处理命令”框中运行上述命令,那么你需要以批处理格式编写,而不是 PowerShell 格式。这意味着应该是:
echo %JOB_NAME%
如果你在运行 shell 命令,那应该是:
echo $JOB_NAME
如果你正在运行 PowerShell 脚本,WRITE-OUTPUT $JOB_NAME
是引用变量的正确方式,但在这种情况下,你可能是在批处理环境中运行 PowerShell 命令。
英文:
JOB_NAME
is the correct variable that holds the name of the job, so I think the problem is the way that you are trying to reference it.
If you are running the above command in an "Execute Windows batch command" box, then you would need to write it in batch format, not powershell format. This means it should be:
echo %JOB_NAME%
If you were running a shell command, it would be:
echo $JOB_NAME
WRITE-OUTPUT $JOB_NAME
is the correct way to reference the variable if you were running a PowerShell script, but in this case you are likely trying to run a PowerShell command in a batch environment.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论