Create Jenkins Job

Action ID: jenkins:job:create
NPM Package:

@backstage-community/plugin-scaffolder-backend-module-jenkins

Description

Create a job jenkins given a name and gitlab repo

Input Schema

PropertyTypeDescriptionRequired
jobXmlstringXML of job used by jenkins to create the job
jobNamestringName of jenkins item
serverUrlstringURL
configPathstringPath to config file of job
folderNamestring-

Output Schema

No output schema defined for this action.

Usage Examples

Create a freestyle job from inline XML

Creates a Jenkins freestyle job using inline XML. Use this when your template renders the job configuration in memory and you want to post it directly to Jenkins.

Copy
steps:
  - id: generate-config
    action: [fetch:template](/backstage/scaffolder-actions/fetch-template/)
    name: Render Jenkins job XML from template
    input:
      url: ./jenkins-templates/freestyle
      targetPath: ./jenkins
      values:
        repoUrl: ${{ parameters.gitlabRepoUrl }}
        branch: main
        serviceName: ${{ parameters.serviceName }}

  - id: create-jenkins-job
    action: jenkins:job:create
    input:
      serverUrl: https://jenkins.ci.company.net
      jobName: ${{ parameters.serviceName }}-build
      jobXml: |
        <?xml version='1.1' encoding='UTF-8'?>
        <project>
          <actions/>
          <description>Build ${{ parameters.serviceName }}</description>
          <keepDependencies>false</keepDependencies>
          <properties/>
          <scm class="hudson.plugins.git.GitSCM" plugin="git">
            <userRemoteConfigs>
              <hudson.plugins.git.UserRemoteConfig>
                <url>${{ parameters.gitlabRepoUrl }}</url>
              </hudson.plugins.git.UserRemoteConfig>
            </userRemoteConfigs>
            <branches>
              <hudson.plugins.git.BranchSpec>
                <name>*/main</name>
              </hudson.plugins.git.BranchSpec>
            </branches>
          </scm>
          <canRoam>true</canRoam>
          <disabled>false</disabled>
          <triggers/>
          <builders>
            <hudson.tasks.Shell>
              <command>make test && make build</command>
            </hudson.tasks.Shell>
          </builders>
          <publishers/>
          <buildWrappers/>
        </project>

Create a job from a rendered config file

Renders a config.xml file into the workspace and creates the Jenkins job from that file. Use this when you manage job XML as a template file in your repository.

Copy
steps:
  - id: render-job-config
    action: [fetch:template](/backstage/scaffolder-actions/fetch-template/)
    name: Render Jenkins config.xml
    input:
      url: ./jenkins-templates/pipeline
      targetPath: ./jenkins
      values:
        repoUrl: ${{ parameters.gitlabRepoUrl }}
        scriptPath: Jenkinsfile
        branch: ${{ parameters.defaultBranch }}

  - id: create-jenkins-job
    action: jenkins:job:create
    input:
      serverUrl: https://jenkins.build.example.com
      jobName: ${{ parameters.serviceName }}-pipeline
      configPath: ./jenkins/config.xml

Create a job inside a Jenkins folder

Creates a pipeline job under a specific Jenkins folder. Use this when organizing jobs by team or domain.

Copy
steps:
  - id: fetch-pipeline-xml
    action: [fetch:plain](/backstage/scaffolder-actions/fetch-plain/)
    name: Fetch prebuilt pipeline XML
    input:
      url: https://gitlab.com/company/ci-templates/-/raw/main/jenkins/pipeline-scm.xml
      targetPath: ./jenkins/pipeline.xml

  - id: create-foldered-job
    action: jenkins:job:create
    input:
      serverUrl: https://jenkins.corp.example.org
      folderName: platform-services
      jobName: ${{ parameters.serviceName }}-deploy
      configPath: ./jenkins/pipeline.xml

Create a multibranch pipeline job for a GitLab repo

Creates a multibranch pipeline that discovers branches in a GitLab repository. Use this when you want Jenkins to build all branches with a Jenkinsfile.

Copy
steps:
  - id: render-mbp-config
    action: [fetch:template](/backstage/scaffolder-actions/fetch-template/)
    name: Render multibranch pipeline config
    input:
      url: ./jenkins-templates/multibranch-git
      targetPath: ./jenkins
      values:
        repoUrl: ${{ parameters.gitlabRepoUrl }}
        includes: "main feature/*"
        scriptPath: Jenkinsfile

  - id: create-multibranch-job
    action: jenkins:job:create
    input:
      serverUrl: https://jenkins.services.example.net
      jobName: ${{ parameters.serviceName }}-mbp
      configPath: ./jenkins/config.xml

Create a pipeline job with inline XML and a custom branch

Creates a Jenkins pipeline job using inline XML with a custom default branch and lightweight checkout. Use this when you need to generate the XML dynamically from user inputs.

Copy
steps:
  - id: create-pipeline-inline
    action: jenkins:job:create
    input:
      serverUrl: https://jenkins.team.example.com
      jobName: ${{ parameters.serviceName }}-pipeline-${{ parameters.environment }}
      jobXml: |
        <?xml version='1.1' encoding='UTF-8'?>
        <flow-definition plugin="workflow-job">
          <actions/>
          <description>Pipeline for ${{ parameters.serviceName }} ${{ parameters.environment }}</description>
          <keepDependencies>false</keepDependencies>
          <properties/>
          <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps">
            <scm class="hudson.plugins.git.GitSCM" plugin="git">
              <userRemoteConfigs>
                <hudson.plugins.git.UserRemoteConfig>
                  <url>${{ parameters.gitlabRepoUrl }}</url>
                </hudson.plugins.git.UserRemoteConfig>
              </userRemoteConfigs>
              <branches>
                <hudson.plugins.git.BranchSpec>
                  <name>*/${{ parameters.defaultBranch }}</name>
                </hudson.plugins.git.BranchSpec>
              </branches>
            </scm>
            <scriptPath>Jenkinsfile</scriptPath>
            <lightweight>true</lightweight>
          </definition>
          <triggers/>
          <disabled>false</disabled>
        </flow-definition>