When fetching Job DSL scripts from a file. How do I accomplish this inside jenkins helm chart jcasc section as well as format?

Viewed 143

What I understand so far: This makes sense, i pass a file in instead of hardcoding the script values

jobs:
  - script: >
      multibranchPipelineJob('configuration-as-code') {
          branchSources {
              git {
                  id = 'configuration-as-code'
                  remote('https://github.com/jenkinsci/configuration-as-code-plugin.git')
              }
          }
      }

jobs:
  - file: ./jobdsl/job.groovy

Current setup: In my jenkins helm values file under jcasc section I have the following. This is good and it works along with other configurations that i am not showing here (not relevant to this discussion)

   JCasC:
      defaultConfig: true
      configScripts:
        pipeline-job: |
          jobs:
            - script: >
                multibranchPipelineJob('testrepo') {
                  branchSources {
                    git {
                      id('testrepo')
                      credentialsId('bitbucketv1')
                      remote('https://bitbucket.org/repo/test.git')
                      includes("master develop")
                      excludes("")
                    }
                  }

Issue:

How do I take my piece of code and pass it as a file like "- file: ./jobdsl/job.groovy". I created a folder inside my jenkins helm folder called jobdsl and add the job.groovy with the multibranchpipelinejob code snippet at start. But I get an error saying file does not exist.

Do I need to create a config map and load this file into jenkins first? Or is there a way to pass the file from local to the jcasc script in my helm chart snippet above? Also what is the correct format of job.groovy? does it include the -script: > part or just from multibranchpipelinejob and down?

0 Answers
Related