Jenkins pipeline sh returnstdout not working - jenkins

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.

Related

How to clone a github repository using Jenkins pipeline script?

I am relatively new to the CI/CD concept.
I am trying to clone a Github repository using declarative pipeline in Jenkins (without SCM).
If i do it without any credentials then I can see in the console output that Jenkins is already trying to clone that repo but it takes extremely long . I can already see that in the Jenkins workspace I have a folder with the name of my github repo but it only has a .git folder inside it and it takes forever but never pulls the repo. After searching on the internet I found out that the permissions of accessing the repository were missing.
Then i added the credentials of my Github repo in Jenkins. I have the following script.
pipeline {
agent any
stages {
stage('clone repo') {
steps {
withCredentials(usernamePassword(credentialsId :jenkins-user-github ,passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME' )){
// Get some code from a GitHub repository
bat("""
git config --global credential.username {GIT_USERNAME}
git config --global credential.helper "!echo password={GIT_PASSWORD}; echo"
git clone https://github.com/aakashsehgal/FMU.git
echo "pulled the code"
""")
}
}
}
}
}
But i get the following error:
Started by user Aakash Sehgal
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\GitHub
[Pipeline] {
[Pipeline] stage
[Pipeline] { (clone repo)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:270)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:291)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:295)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:271)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:271)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.run(WorkflowScript:6)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.delegateAndExecute(ModelInterpreter.groovy:139)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(ModelInterpreter.groovy:663)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(ModelInterpreter.groovy:397)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(ModelInterpreter.groovy:395)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(ModelInterpreter.groovy:662)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:290)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(ModelInterpreter.groovy:546)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(ModelInterpreter.groovy:545)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:278)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:445)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:444)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:277)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(ModelInterpreter.groovy:483)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(ModelInterpreter.groovy:482)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:276)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(ModelInterpreter.groovy:588)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(ModelInterpreter.groovy:587)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:274)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.stageInput(ModelInterpreter.groovy:358)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.stageInput(ModelInterpreter.groovy:357)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:263)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inWrappers(ModelInterpreter.groovy:615)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inWrappers(ModelInterpreter.groovy:614)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:261)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:445)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:444)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:256)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
at sun.reflect.GeneratedMethodAccessor321.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.util.concurrent.FutureTask.run(Unknown Source)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
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
Any idea what am i missing here ?
When utilising the username and password inside the stage, you have a syntax problem. Instead of only {GIT_USERNAME}, you ought to have used ${GIT_USERNAME}.
Having said that, you need to explicitly mention to which branch you need to check out. I assume you'd want to checkout to master branch by default. So use the below:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
// The below will clone your repo and will be checked out to master branch by default.
git credentialsId: 'jenkins-user-github', url: 'https://github.com/aakashsehgal/FMU.git'
// Do a ls -lart to view all the files are cloned. It will be clonned. This is just for you to be sure about it.
sh "ls -lart ./*"
// List all branches in your repo.
sh "git branch -a"
// Checkout to a specific branch in your repo.
sh "git checkout branchname"
}
}
}
}
}
If you want to checkout to a specific branch by default then use the below in your pipeline stage. With the below part, you won't need to run git checkout command separately.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/branchname']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins-user-github', url: 'https://github.com/aakashsehgal/FMU.git']]])
sh "ls -lart ./*"
}
}
}
}

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 - Jmeter Performance report

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

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"

How to add build parameters to jenkins multibranch pipeline?

I would like to add additional build parameters to my jenkins mutibranch pipeline job.
Relevant versions:
org.jenkins-ci.plugins:script-security:1.19
org.kohsuke:groovy-sandbox:1.10
org.jenkins-ci.main:jenkins-war:2.0
org.jenkins-ci.plugins.workflow:workflow-aggregator:2.0
My Jenkins file:
As you can see the first four lines are supposed to add the build parameter option.
import hudson.model.*
def build = Thread.currentThread().executable;
build.addAction(new ParametersAction(new StringParameterValue("SVN_UPSTREAM", build.getEnvVars()['SVN_REVISION'])));
println "SVN_UPSTREAM:" + build.getEnvVars()['SVN_UPSTREAM'];
node('dockerSlave') {
stage 'Checkout'
checkout scm
def mvnHome = tool 'M3'
stage 'VersionSet'
def v = version()
if (v) {
echo "Building version ${v}"
}
sh "${mvnHome}/bin/mvn versions:set -DnewVersion=${env.BUILD_NUMBER}"
stage 'Build'
sshagent(['601b6ce9-37f7-439a-ac0b-8e368947d98d']) {
sh 'echo SSH_AUTH_SOCK=$SSH_AUTH_SOCK'
sh "${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore clean deploy scm:tag"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
}
def version() {
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
matcher ? matcher[0][1] : null
}
Unfortunately i get the following error:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
Scripts not permitted to use staticMethod java.lang.Thread
currentThread at
Is there a way to add the static method to a whitelist or add a build parameter via a different way?
[Pipeline] End of Pipeline
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod java.lang.Thread currentThread
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectStaticMethod(StaticWhitelist.java:174)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:142)
at org.kohsuke.groovy.sandbox.impl.Checker$2.call(Checker.java:180)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:177)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:91)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
at WorkflowScript.run(WorkflowScript:2)
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.GeneratedMethodAccessor210.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:19)
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: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: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
Update:
Seems like disabling the sandbox mode is not possible at the moment.
https://cloudbees.zendesk.com/hc/en-us/articles/207406207-Avoid-script-approvals-with-a-Jenkins-Pipeline-Groovy-script
You should use properties step. Also take a look here at Stackoverflow: How do I use jenkins pipeline properties step?. That is my question where I've learned that you need to explicitly add parentheses even though snippet generator doesn't do that.
Example:
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', name: 'myparam', defaultValue: 'default value']]]])
echo "received ${binding.hasVariable('myparam') ? myparam : 'undefined'}"

Resources