Hi,
I´m using job-dsl 1.48 and today I tried to move my *.groovy
code (pipeline) to separated files in the workspace, located in the
resources directory.
The code looks like:
String script = readFileFromWorkspace("resources/workflowLibs_pipeline2.groovy"))
def multiPipeline = new BitbucketMultiPipeline(
description: script,
name: 'CD/DEV_workflowLibs-multibranch',
displayName: 'Multi branch pipeline test',
bitbucketProjectOwner: "cd",
repoName: "workflowlibs",
includeBranches: ['master*', 'feature/*', 'bugfix/*'],
customScript: script,
usePeriodicTrigger: true
).build(this)
The utility class is doing this DSL commands:
def job = dslFactory.multibranchPipelineJob(name) {
description(description)
displayName(displayName)
orphanedItemStrategy {
discardOldItems {
numToKeep(10)
}
}
if(usePeriodicTrigger) {
triggers {
// Triggers a build periodically if not otherwise run.
periodic(5)
}
}
configure { project ->
project / sources / data / 'jenkins.branch.BranchSource' / source(class: 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource') {
credentialsId "*****" // For scan
checkoutCredentialsId "Bitbucket_Access"
repoOwner(this.bitbucketProjectOwner)
repository(this.repoName)
includes("${includeBranches.join(' ')}")
excludes()
bitbucketServerUrl "https://licdci01.mycompany.net:7993"
autoRegisterHook true
sshPort('7999')
}
if(customScript) {
def factory = project / factory(class: 'com.cloudbees.workflow.multibranch.CustomBranchProjectFactory', plugin: "cloudbees-workflow-template@2.6")
factory << owner(class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject", reference: "../..")
factory << marker()
factory / definition(class: "org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition", plugin: "workfl...@2.29") {
script(customScript)
sandbox true
}
}
}
}
The
job looks fine locally written using FileManagement, and also the
generate job in Jenkins looks fine when invoking /configure on it.
The config.xml looks like:
When running that job in of the Branches, I got this error:
Loading library cd_workflowLibs@FOR_INTEGRATION_TESTING
> git rev-parse --is-inside-work-tree # timeout=10
Setting origin to ssh://g...@licdci01.mycompany.net:7999/cd/workflowlibs.git
> git config remote.origin.url ssh://g...@licdci01.mycompany.net:7999/cd/workflowlibs.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
> git --version # timeout=10
using GIT_SSH to set credentials SSH Bitbucket Access
> git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
> git rev-parse FOR_INTEGRATION_TESTING^{commit} # timeout=10
java.lang.NullPointerException
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: Loading libraries failed
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:516)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:479)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:268)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
The strange thing now is that the generated job works as expected when using a hardcoded String instead of readFileFromWorkspace
// readFileFromWorkspace(...)
def multiPipeline =
Any idea why using readFileFromWorkspace will lead to a broken job, while using String = "// my code" will work ??
I have no idea and played around over hours with File encoding - but without any result yet.
Thanx for your help
Torsten