我正在设置Jenkins管道,但是在传递环境中从外壳程序提取的变量时遇到错误
pipeline {
agent any
environment {
PHP_CHANGE_SET = sh (script: "git diff-tree --no-commit-id --name-only -r HEAD | grep '.php'",returnStdout: true).trim()
}
我被提起错误
[Pipeline] { (Declarative: Post Actions)
[Pipeline] sh
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
Error when executing failure post condition:
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:260)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:262)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
我只需要PHP文件名,它们在commit中并存储在变量中
答案 0 :(得分:0)
如注释中所述,您不能在节点块外部使用它。如果您确实需要执行此操作,并且这是您要做的第一件事(A),则可以做另一件事(B),然后在所需的目录中运行此命令,然后触发此工作(A )。您可以将“ PHP_CHANGE_SET”作为参数,可以从作业B传递。