Comments (8)
@kjenney using job-dsl plugin I am able to create jobs.
I am using the below configurations in the value file. Refer documentation here https://jenkinsci.github.io/job-dsl-plugin/
additionalPlugins:
- job-dsl:1.77
JCasC:
defaultConfig: true
configScripts:
welcome-message: |
jenkins:
systemMessage: Welcome to our CI\CD server. This Jenkins is configured and managed 'as code'.
pipeline-job: |
jobs:
- script: >
pipelineJob('job-dsl-plugin') {
definition {
cpsScm {
scm {
git {
remote {
url('https://github.com/jenkinsci/job-dsl-plugin.git')
credentials('bitBucketUser')
}
branch('*/master')
}
}
scriptPath("JenkinsFile")
lightweight()
}
}
}
from helm-charts.
I have successfully used the following approach, which might be helpful to others:
- As part of the CasC chart values, I have a script that uses the Job-DSL plugin to create a Jenkins job which runs a pipeline that I consider the "seed job root".
The pipeline for this job is defined in a separate file in my repo (in my case/jenkins/pipelines/seed-job-bootstrap.jenkins
), and itself will find and process the individual seed-jobs that also live in my repocontroller: JCasC: configScripts: seed-jobs: | security: # disable if you want to skip manual approval for the scripts used in seed-jobs globalJobDslSecurityConfiguration: useScriptSecurity: false jobs: # Create the seed-job root job - script: > pipelineJob('seed-jobs') { displayName('seed-jobs') // any other properties you want, like triggers, number of runs to keep, etc definition { cpsScm { scm { // point to your own repo where your root seed-job pipeline is defined git { remote { url('https://github.com/my-org/my-repo.git') credentials('my-github-credentials') } branches('*/main') } } scriptPath('jenkins/pipelines/seed-job-bootstrap.jenkins') } } } # Queue a run of the root seed job as part of CasC - script: queue('seed-jobs')
- The
seed-job-bootstrap.jenkins
Jenkins job uses itself thejobDsl
step introduced by the Job-DSL to collect and process all the individual seed-job files that are used to create all my jobs.
In other words, my repo has a individual seed job files defined inside the/jenkins/seed-jobs
folder, each of them creating an individual Jenkins job. The role of theseed-job-bootstrap.jenkins
pipeline is to collect and process them all, something done using thejobDsl
step:def label = "default" // Runs on the default jenkins agent configured by default when installing the helm chart podTemplate( label: label, ){ node (label) { // checkout repo that contains all the individual seed-jobs (This can perfectly be the same repo that contains this very same seed-job-bootstrap.jenkins) stage('checkout') { checkout scm: scmGit( // NOTE: you could pin seed jobs to a branch/tag other than main // branches: [[name: 'refs/tags/${project_tag}']] branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'my-github-credentials', url: 'https://github.com/my-org/my-repo.git']] ) } // Find all the individual seed-jobs and process them, creating the jobs they define stage('create jobs') { jobDsl( removedJobAction: 'DELETE', removedViewAction: 'DELETE', targets: 'jenkins/seed-jobs/*/*.jenkins', lookupStrategy: 'SEED_JOB' ) } } }
If it helps, happy to send a PR and add these steps to the README instructions
from helm-charts.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.
from helm-charts.
This should be documented. I have not been able to successfully created jobs with XML but previously (outside of this chart) been able to create jobs with JCasC.
from helm-charts.
Here is an example of a couple jobs that I was just able to create using this chart (and that have worked with JCasC in the past). NOTE: These depend on an additional plugin (parameterized-trigger:2.35.2).
master:
JCasC:
configScripts:
freestyle-jobs: |
jobs:
- script: >
job('Triggered') {
parameters {
fileParam('build.properties')
}
steps {
copyArtifacts('Triggeranotherjob')
environmentVariables {
propertiesFile('build.properties')
}
shell('echo $AMI_ID;cat build.properties')
}
}
- script: >
job('Triggeranotherjob') {
wrappers {
credentialsBinding {
string('PASSWORD','PASSWORD')
}
}
steps {
shell('echo AMI_ID=test > build.properties;cat build.properties')
}
publishers {
archiveArtifacts('build.properties')
downstreamParameterized {
trigger('Triggered') {
condition('SUCCESS')
parameters {
propertiesFile('build.properties', true)
}
}
}
}
}
from helm-charts.
This plugin is also very useful when seeding default jobs on installation: https://plugins.jenkins.io/job-dsl/
from helm-charts.
@kjenney How did you figure how to configure jobs via JCasC? I haven't found anything about that in the official documentation and the JCasC yaml dump of my running Jenkins has no "jobs" section.
from helm-charts.
There is no good documentation for how to set all of this up. It would be great if someone could write something up specifically for initializing jobs. The instructions for setting up a seed job to then load and run the DSL definitions is good if it works and if you need to continually/automatically update the jobs.
If you are looking for just bootstrapping your jobs and don't expect to add any more jobs, or are willing to just re-provision, there is a simple way to bootstrap jobs via a groovy configuration.
controller:
JCasC:
configScripts:
seed-jobs: |
security:
globalJobDslSecurityConfiguration:
useScriptSecurity: false
jobs:
- url: https://raw.githubusercontent.com/path/to/your/repo/jenkins.groovy
This will setup the pipelines defined in your groovy. For an example jenkins.groovy
:
pipelineJob("p1") {
description("Pipeline P1 is cool.")
displayName("Pipeline P1")
parameters {
choiceParam("Choice", [1, 2], "Note.")
stringParam("Works", "yes", "Is it working?")
}
definition {
cpsScm {
scm {
git {
remote {
url 'https://github.com/path/to/your/repo.git'
}
branch('main')
}
}
// This will be cloned and then ran when Pipeline P1 is ran
scriptPath('path/to/your/job/in/the/repo/Jenkinsfile')
}
}
}
pipelineJob("p2") {
[...]
}
[...]
An example path/to/your/job/in/the/repo/Jenkinsfile
is:
pipeline {
agent any
environment {
CHOICE="${params['Choice']}"
WORKS="${params['Works']}"
}
stages {
stage("S1") {
steps {
echo "step 1"
echo "choice: ${CHOICE}"
echo "works: ${WORKS}"
sleep 10
}
}
stage("S2") {
[...]
}
}
}
from helm-charts.
Related Issues (20)
- Renovate doesn't update CHANGELOG correctly HOT 2
- Renovate doesn't upgrade Jenkins LTS correctly
- Initcontainer throwing error FileSystemException: /root/.cache
- host alias for the agent container
- Use WATCH mode for config reload sidecar
- 4.12.1 -> default installPlugins are causing versioning issues HOT 1
- Jenkins wont start after 5.1 upgrade HOT 7
- Issues with agent.image map HOT 3
- Getting error while installing helm build HOT 6
- The Pod template configuration of k8s cloud is lost HOT 2
- useJenkinsProxy is not rendered in template
- Document installation using proxy set up with user and password
- jenkinsTunnel in the values.yaml should include a comment not to include protocol like https://
- k3s: Crash on startup after Helm apply HOT 3
- FR: Worker only deploying though chart
- Can't disable Jenkins login page
- Jenkins plugins not getting upgraded through helm chart HOT 1
- Add ability to provide annotations to the jcasc config configmap
- A thread (Download metadata thread/63) died unexpectedly due to an uncaught exception
- Tiltfile contains deprecated usage of controller.adminPassword HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helm-charts.