I want to keep Jenkins parametrized scheduler configuration in a file in git.
It would be very convenient if there is a way to update a job parametrized scheduler configuration via a custom script which reads the config file from repo and post it to the job.
Is there such functionality in Jenkins API?
Related
I would like to set up many jobs automatically. In the build step "Process Job DSLs", the job-dsl plugin allows to either "Use the provided DSL script" or "Look on Filesystem" for doing its thing. While "Look on Filesystem" looks like what I'm looking for, since it allows to define multiple Job DSL files at once, it sources them from a directory on the Jenkins server. I would rather have it fetch those job specifications from a remote Git repository.
Therefore, is it possible to source all jobs from a remote Git repository? Somehow like this pseudo code?
We are setting up the job to generate executable file by gathering different components (All these tagged) , We need a way to get these components based on the name of the build, I know copy artifacts will do but i would like to put this on script, Is there way (Api or something else) can download archived artifacts? once all these components present it is easy to create a installer
I have tried there are multiple curl and wget commands which accept username and password , But I need something without username and password as script runs on jenkins workspace we dont need to pass the password
If you want to interact with Jenkins via scripts there are two ways:
1. Jenkinspipeline
With Jenkinspipelines you can define the builds with Groovy scripts whereby you can use copyArtifact via the Groovy DSL. Its not actually a script its a build definition defined with a Groovy DSL. This should be the way when a Jenkins Job is gathering stuff from other Jobs.
https://jenkins.io/doc/book/pipeline/
2. Jenkins CLI
With the Jenkins CLI you can interact with Jenkins via a shell script. This should be the way when you want to gather stuff from outside of Jenkins.
https://wiki.jenkins.io/display/JENKINS/Jenkins+CLI
If Jenkins is secured then I think you will have to provide credentials when using the Jenkins CLI. With Jenkinspipelines you don't need credentials, because they are executed in Jenkins. But you need to define permissions on the Jenkins Jobs (or in the Pipelines) so that Jenkins Jobs can access Artifacts of other Jobs. (CopyArtifactPermission)
Is there a way to configure the JaCoCo Jenkins Plugin coverage threshold through a shell script or API? For ex: I want to make an app to change code coverage threshold values for my Jenkins Jobs. How would I do it if I want my Jenkins instance abstracted?
Okay, turns out its a bit simple really. Plugin configurations are stored in an XML file. Global configurations in .jenkins root folder and job specific configurations in $HOME/.jenkins/jobs/{JOB_NAME}/config.xml.
Modify the config.xml file to store new configurations. This configuration file is exposed by each job at http://<SERVER>:<PORT>/jenkins/job/<JOB NAME>/config.xml. Since Jenkins loads this data at first load, you need to execute 'Reload Configuration From Disk' in Global configuration.
Since we're updating the XML from an API, you need to tell jenkins to reload configuration from an API as well. To do that, execute a shell to use jenkins_cli.jar's reload-configuration command.
Reference : Does anyone know how to reload hudson configuration without restarting?
Create Jenkins Seed Job using DSL Plugin - Where i can pass Git Repo location to create the Jenkins jobs for the repo. The Job is created programmatically in the repo. Seed Job should read the groovy file in the repo and create the new job.
You can :
Checkout Groovy file from Seed Job
Access file programmatically from code of Seed Job (some SCM tools provide API, ie. Bitbucket, github)
I have 15 Jenkins jobs configured in order to implement a specific flow. I am improving and editing these jobs as time goes by.
Is there a way to save all these jobs and its configurations to a repository or at least in the form of export jobs, save it and import when needed?
There are two plugins that will help you save Jenkins jobs, "SCM Sync configuration" and "JobConfigHistory" defined at the wiki.jenkins-ci.org website.
SCM Sync Configuration Plugin (which keeps the config in a SCM repository)
or
Job Config History Plugin (Saves copies of all job and system configurations)
The Job DSL Plugin allows to define the jobs in a DSL and store the DSL scripts in a SCM repo. The DSL increases the readability of the config files in contrast to the XML format.
For an intro, see the slides and video from the Configuration as Code: The Job DSL Plugin talk at the Jenkins User Conference 2015 in London.
You can move/copy jobs to another destination simply by copying directory with job (default path for jobs directories is /var/lib/jenkins/jobs).
You can get more info here - https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins
The Workflow feature may let you write your entire process as one (Groovy) script, which you can then maintain in your version control system alongside other sources.