Jenkins Pipeline - Jmeter Performance report - jenkins

I have the below Jenkins pipeline script to run the jmeter tests and make a report from a JTL file
node('master') {
stage 'Run JMeter Test'
def workspace = pwd()
def jmeterTestFile = 'jenkins_test'
echo "workspace = ${workspace}"
echo "env.WORKSPACE = ${env.WORKSPACE}"
bat "${workspace}\\jmeter\\bin\\jmeter.bat -n -t ${workspace}\\jmeter_scripts\\${jmeterTestFile}.jmx -l ${workspace}\\jmeter_scripts\\${jmeterTestFile}_results.jtl"
step([$class: 'ArtifactArchiver', artifacts: 'CP-Perf-Report.html,**/*.jtl, **/jmeter.log', fingerprint: true])
//perfReport "jmeter_scripts\\${jmeterTestFile}_results.jtl"
performanceReport parsers: [[$class: 'JMeterParser', glob: "jmeter_scripts\\${jmeterTestFile}_results.jtl"]], relativeFailedThresholdNegative: 1.2, relativeFailedThresholdPositive: 1.89, relativeUnstableThresholdNegative: 1.8, relativeUnstableThresholdPositive: 1.5
}
Initially I tried creating report with perfReport "jmeter_scripts\\${jmeterTestFile}_results.jtl" command but it was failing with FileNotFoundException so I tried alternative way using performanceReport parsers but even then its failing again with FileNotFoundException but I can manually open the c:\tools\jenkins\workspace\PerformanceTesting\jmeter_scripts\jenkins_test_results.jtl file and see the test report. can anyone help me to fix this issue?
workspace = c:\tools\jenkins\workspace\PerformanceTesting
[Pipeline] echo
env.WORKSPACE = c:\tools\jenkins\workspace\PerformanceTesting
[Pipeline] step
Archiving artifacts
Recording fingerprints
[Pipeline] step
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.FileNotFoundException: c:\tools\jenkins\workspace\PerformanceTesting\jmeter_scripts\jenkins_test_results.jtl (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at hudson.plugins.performance.parsers.ParserDetector.detect(ParserDetector.java:21)
at hudson.plugins.performance.parsers.ParserFactory.getParser(ParserFactory.java:26)
at hudson.plugins.performance.PerformancePublisher.getParsers(PerformancePublisher.java:439)
at hudson.plugins.performance.PerformancePublisher.perform(PerformancePublisher.java:481)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:59)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Finished: FAILURE

I don't see any sign of running a JMeter test in the log so I would recommend amending your pipeline script as follows:
Convert \\ slashes into / ones
Given you are running your test on Windows I believe you should be using variables in form of %WORKSPACE% rather than ${workspace}
See following guides for references:
Building a software project
Running a JMeter Test via Jenkins Pipeline - A Tutorial

Related

Running groovy script at the end of Jenkins Job

I need to run a groovy Post-Build script to do some clean up so I have arranged the following script:
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = '/usr/bin/docker stop mysql'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
Although the command '/usr/bin/docker stop mysql' works if I log on the machine, when the groovy script is executed, the following error is raised:
java.io.IOException: Cannot run program "/usr/bin/docker": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at org.codehaus.groovy.runtime.ProcessGroovyMethods.execute(ProcessGroovyMethods.java:533)
at org.codehaus.groovy.runtime.dgm$894.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:104)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
at org.kohsuke.groovy.sandbox.impl.Checker$checkedCall$0.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at Script1.run(Script1.groovy:2)
Do you know why the groovy engine fails to find the 'docker' command?
Thanks!
The Groovy Postbuild plugin actually runs on the master, not on the build node. The documentation states:
This plugin executes a groovy script in the Jenkins JVM
which is presumably meant to convey "and not in an agent JVM". (Fun side note: If you use println in the Groovy script, it prints out to the Jenkins master log, not to the job's console log)
The Post build task plugin does run on the build node (and you don't need to wrap your shell command in a groovy script). The task requires a condition: to "always run" your script just leave the Log text blank.
You might also consider taking a look at the Jenkins Pipeline, which lets you bake in try/catch type logic and maintain your pipeline "as code" using a Jenkinsfile.

Navigating to .jar via sh

Very new to jenkins so I apologize, getting the following while running my jenkins job:
Now mvn clean install
[Pipeline]
echo Now Archiving...
[Pipeline]
archiveArtifacts Error when executing success post condition:
hudson.AbortException: No artifacts found that match the file pattern
"**/target/*.jar". Configuration error? at
hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:253) at
org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
at
org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
at
org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:50)
at hudson.security.ACL.impersonate(ACL.java:290) at
org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
Source) at java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
java.lang.Thread.run(Unknown Source)
Archiving artifacts ‘/target/*.jar’ doesn’t match anything: ‘’
exists but not ‘**/target/*.jar’ [Pipeline] }
I'm trying to get it to simply build and find the .jar for now, then I will look into scp to my EC2 for a deployment stage.
Thanks
Git: https://github.com/BillyCharter87/Tech-O-Dex-API/blob/master/Jenkinsfile
Have you confirmed if the files actually exists in your workspace after a build occurs??
def fileExists = fileExists '**/target/surefire-reports/TEST-*.xml'
if (fileExists) {
junit fileExists
} else {
echo 'Sorry file does not exist have you skipped test ???'
}
you can add this if you want in your code, checks if the file exists.
P.S. trying mention the absolute PATH from the workspace and see if that works
Hope it helps :)

Printing code coverage status on pull request for Bitbucket stash based repository using JenkinsFile

I currently have a private Bitbucket stash repository e.g. https://xyzgit.company.com/stash/scm/proj1/subproj2.
This is a gradle based project which uses JenkinsFile to manage different stages for Jenkins Job (including setup, build, publish etc). Whenever a new change is committed to a branch, it automatically triggers a build or provide an option to trigger a build. To analyse code coverage, we use Jcoco Plugin which analyzes all subfolders to get the coverage.
My current requirement is to print code coverage status on the pull request after the build is successful over jenkins using JenkinsFile.
I came across a plugin i.e. Bit Bucket Code Coverage Plugin but I did not find any such plugin available to be installed in my Jenkins Environment. I tried to do it manually but it redirects me to plugin available for Github.
I anyway installed that and tried what is suggested in the document i.e. adding these two lines in my Jenkins File :
step([$class: 'MasterCoverageAction', scmVars: [GIT_URL: "https://xyzgit.company.com/stash/scm/proj1/subproj2"]])
step([$class: 'CompareCoverageAction', scmVars: [GIT_URL: "https://xyzgit.company.com/stash/scm/proj1/subproj2"]])
It did not work. I got the following Error :
[GitHub PR Status] Attempt to discover PR for null # null
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.FileNotFoundException: https://api.github.com/repos/stash/scm
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0
(HttpURLConnection.java:1872) at sun.net.www.protocol.http.
HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.
getResponseCode(HttpsURLConnectionImpl.java:338)
at org.kohsuke.github.Requester.parse(Requester.java:602)
Caused: java.io.FileNotFoundException:
https://api.github.com/repos/stash/scm
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.
newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.
newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.
run(HttpURLConnection.java:1926)
at sun.net.www.protocol.http.HttpURLConnection$10.
run(HttpURLConnection.java:1921)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.
getChainedException(HttpURLConnection.java:1920)
at sun.net.www.protocol.http.HttpURLConnection.
getInputStream0(HttpURLConnection.java:1490)
at sun.net.www.protocol.http.HttpURLConnection.
getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.
getInputStream(HttpsURLConnectionImpl.java:254)
at org.kohsuke.github.Requester.parse(Requester.java:612)
at org.kohsuke.github.Requester.parse(Requester.java:594)
at org.kohsuke.github.Requester._to(Requester.java:272)
Caused: org.kohsuke.github.GHFileNotFoundException: {"message":"Not
Found","documentation_url":"https://developer.github.com/v3"}
at org.kohsuke.github.Requester.handleApiError(Requester.java:686)
at org.kohsuke.github.Requester._to(Requester.java:293)
at org.kohsuke.github.Requester.to(Requester.java:234)
at org.kohsuke.github.GitHub.getRepository(GitHub.java:443)
at com.github.terma.jenkins.githubprcoveragestatus.
GitHubPullRequestRepository.getGitHubRepository
(GitHubPullRequestRepository.java:57)
Caused: java.io.IOException: Could not retrieve GitHub repository named
stash/scm (Do you have properly set 'GitHub project' field in job
configuration?) at com.github.terma.jenkins.githubprcoveragestatus.
GitHubPullRequestRepository.getGitHubRepository
(GitHubPullRequestRepository.java:59) at
com.github.terma.jenkins.githubprcoveragestatus.
GitHubPullRequestRepository.getPullRequestFor
(GitHubPullRequestRepository.java:32)
at com.github.terma.jenkins.githubprcoveragestatus.
PrIdAndUrlUtils.getMultiBranch(PrIdAndUrlUtils.java:63)
at com.github.terma.jenkins.githubprcoveragestatus.
PrIdAndUrlUtils.getPrId(PrIdAndUrlUtils.java:72)
at com.github.terma.jenkins.githubprcoveragestatus.
CompareCoverageAction.perform(CompareCoverageAction.java:93)
at org.jenkinsci.plugins.workflow.steps.
CoreStep$Execution.run(CoreStep.java:80)
at org.jenkinsci.plugins.workflow.steps.
CoreStep$Execution.run(CoreStep.java:67)
at org.jenkinsci.plugins.workflow.steps.
SynchronousNonBlockingStepExecution$1$1.
call(SynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:260)
at org.jenkinsci.plugins.workflow.steps.
SynchronousNonBlockingStepExecution$1.
run(SynchronousNonBlockingStepExecution.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.
runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.
run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
Can anybody help me if any additional setting is there? or How to inject env CHANGE_URL and CHANGE_ID in JenkinsFile ?
Take a look at Code Coverage Plugin for Bitbucket Server. In it's repo you could find maven-based client which supports JACOCO and could be easily called from gradle.

Jenkins pipeline sh returnstdout not working

I am attempting to use the returnStdout feature of the Jenkins pipeline sh command. defined here https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script
Pulling from previous question and answers: Is it possible to capture the stdout from the sh DSL command in the pipeline
My original code:
node{
def output = sh(returnStdout: true, script: 'pwd')
println "output = ${output}"
}
and its result. You can see that I am getting exit code instead of the result passed into my variable:
[Pipeline] node {
[Pipeline] sh
[Update_Stageing_DB] Running shell script
+ pwd
/mnt/storage/jenkins/workspace/Update_Stageing_DB
[Pipeline] echo
output = 0
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
Finished: SUCCESS
Based on the examples I figured I might need to add the .trim() so my updated code looks like this:
node{
def output = sh(returnStdout: true, script: 'pwd').trim()
println "output = ${output}"
}
But this results in the entire job to fail:
[Pipeline] node {
[Pipeline] sh
[Update_Stageing_DB] Running shell script
+ pwd
/mnt/storage/jenkins/workspace/Update_Stageing_DB
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.trim() is applicable for argument types: () values: []
Possible solutions: wait(), grep(), wait(long), times(groovy.lang.Closure), div(java.lang.Character), print(java.io.PrintWriter)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
at WorkflowScript.run(WorkflowScript:3)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:74)
at sun.reflect.GeneratedMethodAccessor771.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:277)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
Im sure i'm missing something basic but for the life of me I cant see whats wrong with this simple code. Any help would be appreciated.
Jenkins ver. 2.32.2
No signature of method: java.lang.Integer.trim() is applicable
That error message means that the sh step is returning a numeric value.
For me, this only occurs if I use the returnStatus parameter rather than returnStdout in the sh step invocation.
Make sure that your plugins are up-to-date, and that you're using the correct parameter; you can use the "Replay" link in the sidebar on any build page to see exactly which Pipeline script(s) was loaded, if you're loading the Pipeline from a remote SCM, for example.
Also, in case you really only need to run pwd in the shell step, you can simplify a bit by using the pwd Pipeline step.

Jenkins Pipeline conditional stage succeeds but Jenkins shows build as failed

Jenkins version = 2.19
Jenkins Multibranch Pipeline plugin version = 2.92
I have a Jenkinsfile with a few conditional stages based on the branch.
Here is a modified for the sake of brevity version of my Jenkinsfile:
node {
stage('Checkout') {
checkout scm
}
stage('Clean Verify') {
sh 'mvn clean verify'
}
if (env.BRANCH_NAME == "develop") {
stage('Docker') {
sh 'mvn docker:build -DpushImage'
}
}
}
I am using the multibranch pipeline plugin.
It successfully detects and builds all my branches.
The problem I have is that all builds report as failed even though if i hover each stage it reports 'Success'.
I have attached an image showing a feature branch where the two stages i wanted to run have run and completed with success but you can see the build has actually reported as failed.
I get the exact same outcome for develop branch as well - it executes the Docker stage successfully but the build reports failed.
My expectation is that each branch will report success as the stages that ran for that branch all passed.
EDIT 1
Here's the end of the build log (i'm hoping this is sufficient as i didn't want to pick out all the private info but let me know if required)
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.459 s
[INFO] Finished at: 2017-02-21T15:13:02+11:00
[INFO] Final Memory: 84M/769M
[INFO] ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[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
[Pipeline] End of Pipeline
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:253)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:126)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
at WorkflowScript.run(WorkflowScript:93)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor501.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
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.
I know this is old, but I ran into a similar issue with a declarative pipeline and landed here. As it turns out, I was trying to use a sh to set an environment variable within the pipeline block, but my main agent was none, i.e.:
pipeline {
agent none
environment {
VERSION = sh(returnStdout: true, script: 'git describe --tags')
}
}
That resulted in the same error Required context class hudson.FilePath is missing. Moving it to a stage with an agent worked as expected.
my solution for the error Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
is:
#!/usr/bin/env groovy
import hudson.model.*
node('master') {
sh("your shell script")
}
In my case, it suddenly stopped working, with the error:
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
The reason was that the node was simply down. Had to restart it and relaunch its agent (it was slave).
The sh command is not closed with a quote in the end.
This error can happen if your branch gets deleted and will show the below error:
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException:
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException:
Required context class hudson.FilePath is missing 14:25:07 Perhaps
you forgot to surround the code with a step that provides this, such
as: node
and THEN at the end it will also say:
ERROR: Couldn't find any revision to build. Verify the repository and
branch configuration for this job.
In our case we had sometimes set a job to use a branch that was still in a PR and once the PR was merged the branch was auto-deleted (e.g. https://stackoverflow.com/a/57328204/292408).
Restore the branch in the job if this is your case and it should work again. If you are seeing this error inconsistently then this might be your issue.
I had this error:
Error when executing always post condition: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
It was caused by ambiguous interpolation:
environment {
FILE = "some-$BRANCH.yml"
}
The correct expression in this case would be:
"some-${BRANCH}.yml"

Resources