html tool

2021年4月7日星期三

解决:MissingContextVariableException: Required context class hudson.FilePath is missing

 https://stackoverflow.com/questions/42380712/jenkins-pipeline-conditional-stage-succeeds-but-jenkins-shows-build-as-failed

问题: 

MissingContextVariableException: Required context class hudson.FilePath is missing

code:  jenkins-pipeline 

def jobes = [:]

def lists=["xls","doc","ole","exe86"]

def  props = readJSON file: '/home/sandbox/lj_test/code_backup/input.json'

def total=lists.size()

for (int i = 20; i >15; i--) {

  def sandbox_id = i

  def sample=lists[i-20]

  def props_d = props["${sample}"]

...

}

解决:

So after looking more closely at the log file it helped me to track down the problem.

It's worth noting that clicking on the build stage to view the logs is what threw me - this is what I had been doing. When I actually went to the full console log output i saw the error about:

Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node

Underneath the node {} section that I had I had a statement for deploys:

def branch = readFile('branch').trim()
if (branch == master) {
    ...
}

The problem was that the readFile statement was defined outside of a node.

The answer was to put the readFile statement within a node {} section.



没有评论:

发表评论