How to use job-template and project in Jenkins Job Builder

188 Views Asked by At

I am trying to understand how the job-templates and projects are supposed to be used. After reading the documentation I came up with this:

- project:
name: project-name
jobs:
  - 'alcatel-pipeline':
      svnurl: "svn://sourcecontrol/java/testing/swright-pipeline-test/trunk"
  - 'other-pipeline':
      svnurl: "svn://sourcecontrol/java/testing/swright-pipeline-test/trunk"

- job-template:
name: '{name}'
project-type: pipeline
pipeline-scm:
  scm:
    - svn:
        url: '{svnurl}'
        clean: true
  script-path: Jenkinsfile
  lightweight-checkout: true

My thought was that for each item in project.jobs the job-template would render a job with the variables substituted. But what I get is the following error:

jenkins_jobs.errors.JenkinsJobsException: Failed to find suitable template named 'alcatel-pipeline'

The documentation seems to indicate that I need to have a job-template for every item in project.jobs. But I dont see how thats useful for my use case, which is that I have about 150 pipeline jobs that only differ in the name and the SCM URL.

How do I define one job-template and the data to render multiple job configurations?

1

There are 1 best solutions below

0
On

Ok this seems a little convoluted, but it works, and its also described this way in the documentation.

- project:
name: pipeline
jobs:
  - '{id}-{name}':
      id: "alcatel"
      svnurl: "svn://sourcecontrol/java/testing/swright-pipeline-test/trunk"
  - '{id}-{name}':
      id: "other"
      svnurl: "svn://sourcecontrol/java/testing/swright-pipeline-test/branches/test"

- job-template:
    name: '{id}-{name}'
    project-type: pipeline
    pipeline-scm:
      scm:
        - svn:
           url: '{svnurl}'
           clean: true
      script-path: Jenkinsfile
      lightweight-checkout: true