I am very new to Jenkins – I am trying to run a multibranch pipeline script on Jenkins version 2.375.1. The builds are triggered with commits and PR’s filed on Github. On committing a new file or initiating a PR, Jenkins auto triggers a build but consistently stops as it hits this issue.
org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected char: ” @ line 1, column 2.
{rtf1ansiansicpg1252cocoartf2513
I have added a Jenkinsfile.Jenkinsfile and Example.groovy script in my repo with this code ->
Jenkinsfile.Jenkinsfile (note the .Jenkinsfile extension is hidden in the repo)
node {
// Git checkout before load source the file
checkout scm
// To know files are checked out or not
sh ”’
ls -lhrt
”’
def rootDir = pwd()
println(“Current Directory: ” + rootDir)
// point to exact source file
def example = load “${rootDir}/Example.Groovy”
example.exampleMethod()
example.otherExampleMethod()
}
Example.groovy (Note the .groovy extension is hidden in repo)
import hudson.slaves.EnvironmentVariablesNodeProperty
import hudson.EnvVars
import jenkins.model.*
jenkins = Jenkins.instance
EnvironmentVariablesNodeProperty prop = jenkins.getGlobalNodeProperties().get(EnvironmentVariablesNodeProperty.class)
EnvVars env = prop.getEnvVars()
def MY_VAR = env[‘MY_JENKINS_VAR’]
def exampleMethod() {
println(“exampleMethod”)
}
def otherExampleMethod() {
println(“otherExampleMethod”)
}
return this