如何显示 Jenkins 自由风格作业的作业名称?

huangapple go评论57阅读模式
英文:

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

 &quot;c:\myjobs\&lt;thejobnamevalue&gt;\dev\app.sln&quot;

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.

huangapple
  • 本文由 发表于 2023年3月7日 13:33:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定