0
votes

My use case: I want to set up a Jenkins configuration via the Jenkins Helm chart, using the JCasC plugin. I would also like to define a number of jobs via the Pipeline plugin in a series of Jenkinsfiles, so that the entire setup is configured in code, with a clean, complete installation able to be performed just by running helm install.

However, I'm having trouble loading my Pipeline scripts. In my JCasC, I have defined a Job DSL seed script as follows:

job('seedJob') {
  scm {
    git {
      remote {
        url 'ssh://git@foo/bar.git'
        credentials 'creds'
      }
    }
  }
  steps {
    dsl {
      external 'jenkins/jobs/*.groovy'
    }
  }
}

This successfully pulls the scripts from the repo, an example of which is:

pipeline {
   // hello.groovy
   // Do stuff
}

However, the job fails when parsing the Pipeline script with the following error:

ERROR: (hello.groovy, line 1) No signature of method: hello.pipeline() is applicable for argument types: (hello$_run_closure1) values: [hello$_run_closure1@4c6f43b6]
Possible solutions: pipelineJob(java.lang.String), pipelineJob(java.lang.String, groovy.lang.Closure)
Finished: FAILURE

My suspicion is that Pipeline scripts can't be read this way via Job DSL. If this is the case, is there are way I can achieve the loading of multiple Pipeline scripts from a single seed job?

1

1 Answers

0
votes

Seed jobs should look like:

pipelineJob('job_name_here') {
  definition {
    cpsScm {
      scm {
        git {
          branches('*/master')
      branches('*/release')
          remote {
            credentials('credentials_id_from_jenkins_here')
            name('name')
            url('git@gitlab_repo_here.git')
          }
        }
      }
    }
  }
  triggers {
    gitlab {
      ciSkip(true)
      triggerOnPush(true)
      triggerOnMergeRequest(false)
      triggerOnClosedMergeRequest(true)
      branchFilterType('RegexBasedFilter')
      targetBranchRegex('(.*master.*|.*release.*)')
      secretToken('paste_secret_token_for_webhook_here')
    }
  }
}