Im trying to build a pipeline on Jenkins that runs a command on node and informs me of the following error:
groovy.lang.MissingPropertyException: No such property: api 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:289)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:293)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
i dont know the node command its an error command or its for another error this is de pipeline file:
def call() {
pipeline {
agent any
parameters {
string(name: 'branch', defaultValue: 'refs/heads/develop', description: 'git branch where fetch sourcecode')
}
environment {
GIT_URL = getGitRepoURL()
GIT_CREDENTIALS = '*******'
}
tools {
nodejs "node"
}
triggers {
cron('H 06 * * 1-5')
}
stages {
stage ('Initialize'){
steps {
echo 'initializing'
deleteDir()
bat '''
echo "PATH = %PATH%"
echo "M2_HOME = %M2_HOME%"
'''
}
}
stage ('Sourcecode'){
steps {
echo 'fetching sourcecode from ' + env.GIT_URL
checkout([$class: 'GitSCM', branches: [[name: params.branch]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: env.GIT_CREDENTIALS, url: env.GIT_URL]]])
}
}
stage ('Execute raml2html'){
steps {
sh 'cd ..\HelpDevelopsAPI
node raml2html -s %WORKSPACE% -c %WORKSPACE%\..\apidef-aqj-commons -o /server/api --cat .*.html --schema /server/schema/%JOB_BASE_NAME% --mock /server/mock/%JOB_BASE_NAME%
cd %WORKSPACE%'
}
}
}
}
}
def getGitRepoURL() {
String projectName = env.JOB_BASE_NAME
print 'projectName '+projectName +'\n'
String[] projectParts = projectName.tokenize( '-' )
String bian = projectParts[1]
String name = projectParts[0]+'-'+projectParts[1]+'-'+projectParts[2]
echo 'exampleurl'+bian+'/'+name+'.git'
return 'exapleurl'+bian+'/'+name+'.git'
}
The binding is defined in the Groovy API documentation as follows: “Represents the variable bindings of a script which can be altered from outside the script object or created outside of a script and passed into it.”.
Class MissingPropertyExceptionAn exception occurred if a dynamic property dispatch fails with an unknown property. Note that the Missing*Exception classes were named for consistency and to avoid conflicts with JDK exceptions of the same name. See Also: Serialized Form.
It can be used to orchestrate your pipeline in Jenkins and it can glue different languages together meaning that teams in your project can be contributing in different languages. Groovy can seamlessly interface with the Java language and the syntax of Java and Groovy is very similar.
The error you see means that jenkins is finding the word api
in your script and tries to interpret is a variable or command of jenkins, and doesn't find a match. I searched for the word api
in your script and saw 2 issues:
%VAR%
) in a bash step. You should be using $VAR
instead.Try changing:
sh 'cd ..\HelpDevelopsAPI
node raml2html -s %WORKSPACE% -c %WORKSPACE%\..\apidef-aqj-commons -o /server/api --cat .*.html --schema /server/schema/%JOB_BASE_NAME% --mock /server/mock/%JOB_BASE_NAME%
cd %WORKSPACE%'
to:
sh '''cd ..\HelpDevelopsAPI
node raml2html -s $WORKSPACE -c $WORKSPACE\..\apidef-aqj-commons -o /server/api --cat .*.html --schema /server/schema/$JOB_BASE_NAME --mock /server/mock/$JOB_BASE_NAME
cd $WORKSPACE'''
You're mixing Windows-specific constructs/syntax in the shell task step. In addition to the suggestions made by @vasiliki-siakka: replace the backslash directory separators \
in your strings with forward slash /
, and surround the variables with "
(double quotes) to handle potential spaces in directory names:
sh '''
cd ../HelpDevelopsAPI
node raml2html -s "${WORKSPACE}" -c "${WORKSPACE}/../apidef-aqj-commons" -o /server/api --cat .*.html --schema "/server/schema/${JOB_BASE_NAME}" --mock "/server/mock/${JOB_BASE_NAME}"
cd "${WORKSPACE}"
'''
OR
if your Jenkins runs on Windows, use the bat task step, and reference the variables in Windows style %VARIABLE_NAME%
, but you still have to escape the backslashes like this \\
because the Jenkinsfile
syntax is Groovy based. Untested example:
bat '''
cd "%WORKSPACE%"
node raml2html -s "%WORKSPACE%" -c "%WORKSPACE%\\..\\apidef-aqj-commons" -o \\server\\api --cat .*.html --schema "\\server\\schema\\%JOB_BASE_NAME%" --mock "\\server\\mock\\%JOB_BASE_NAME%"
cd "${WORKSPACE}"
'''
I had a similar issue -
No such property: config for class: groovy.lang.Binding error
In my JenkinsFile, I was referencing an object named config
- i checked previous version and realised I'd deleted a config object
No such property: config for class: groovy.lang.Binding error
Search your jenkins file and see if you're using an undeclared object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With