Create a job jenkins given a name and gitlab repo
Input Schema
| Property | Type | Description | Required |
|---|---|---|---|
| jobXml | string | XML of job used by jenkins to create the job | |
| jobName | string | Name of jenkins item | |
| serverUrl | string | URL | |
| configPath | string | Path to config file of job | |
| folderName | string | - |
Output Schema
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.
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.
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.xmlCreate a job inside a Jenkins folder
Creates a pipeline job under a specific Jenkins folder. Use this when organizing jobs by team or domain.
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.xmlCreate 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.
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.xmlCreate 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.
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>