How to use configuration management to configure Jenkins? - jenkins

I am looking for a way to add/remove/update Jenkins master environment variables using some way of configuration management.
If this can be done with Ansible even better.
Please note that I would like to avoid patching the config.xml file manually, especially because this would risk to create issues and a Jenkins restart would be required and this is to be avoided whenever is possible.
In case it was not clear, I am trying to find an automation solution for altering Manage Jenkins - Configure System - Global properties.

you can configure all your Jenkins master using groovy.
I just did the same when we upgrade to Jenkins 2.
here are some links : https://pghalliday.com/jenkins/groovy/sonar/chef/configuration/management/2014/09/21/some-useful-jenkins-groovy-scripts.html
https://github.com/DotCi/jenkinsci-dotci-example/blob/master/configure-dotci.groovy
https://gist.github.com/vrivellino/97954495938e38421ba4504049fd44ea
BTW , you can install your plugins using CLI it will save you time in the future.
and you can create all your jobs using DSL , so all changes will be in github.
if you have specific question , let me know

Related

Jenkins Bitbucket SSDT Continous Integration DevOps Process

CICD Process with Jenkins, Bitbucket, SSDT(SQL Server Data Tools).
Please list out the steps to perform CICD Process.
Including what plugins i need to install in Jenkins for SSDT(SSIS-ISPAC file) or SQL Database Solution(DAPAC file)
This question is very broad and as with all the stuff related to databases the best answer would be "it depends". As far as I know that there is no proper plugins either for Jenkins nor for Bitbucket that work with SSDT very well so you'll need to implement all your actions by yourself.
It will depend on your system how the pipeline should look like. There are a lot of questions that you'll need to answer first but without knowing your exact situation it is very hard to suggest you something specific. Example questions:
How many environments do you have?
Do you have tests?
Can somebody change the state of the destination database manually, passing the CI/CD pipeline?
Will you run publish on every commit?
Do you trust what SSDT will decide how to publish database? (Mostly people would like to preview the script that would be executed on prod)
Then after answering these questions you'll might know what will you need. After that you need prepare the proper publish script, exclude/ignore/add object types you'd like to deploy and use MSBuild.exe and SQLPackage.exe command line utilities. You'll run these utilities with specific set of arguments and paths to the publish configs, DACPACs, etc. Bamboo and Jenkins supports command line commands for that.

Should we use different server for automation scripts

This is a not related to code fix, but a general approach for test automation.
I have a test automation written in javascript which runs perfectly on my machine as well as my local jenkins.
Now, i want to use my company's server(centOS) and jenkins so that it is accessible to everyone in my organization.
Issue: nodejs version in company's server need update to run my automation, but server team wont do it since they are not sure if any other functionality used be other teams may start to break because of the upgrade.
Have you faced this situation. Do you have different servers for core code and automation scripts. Please suggest.
This is a complex situation that really depends on many variables. I would recommend using an agent that contains the proper version of Nodejs. With this solution you can leave the current build server how it is but you can also use the exact version of node you need. This will require an extra server/VM with the Jenkins slave software but this will remove the need to change the master server.
The solution my company went with is using Jenkins 2.x with Declarative pipelines and ephemeral Docker containers for builds. This allows you to use any Docker image such as the official Node image. You can pin a version and build it with that. With this there is no need to worry about the version on the server. Jenkins Master doesn't even need to actually build.

Precautions while upgrading Jenkins 1.631 to 1.651.3

Could you please let me know what precautions need to be taken while upgrading Jenkins from 1.631 to 1.651.3 other than config.xml of Jenkins and Jobs along with Plugins.
I have 'n' no# of jobs configuration and how to achieve the roll back.
It is recommended to check change-log from official site first, as people use different functions / plugins in different way. And you can install the new version in different host, to check your jobs before applying to production env.

Using Jenkins CLI to configure plugins

I am working on installing and configuring Jenkins automatically using the Jenkins CLI. I am able to install plugins such as the Active Directory plugin, but haven't figured out how to configure it. Is it possible to perform such tasks from the CLI? From a Jenkins GUI standpoint, I'd like to check the Enable security checkbox under Security Realm check the Active Directory option, provide parameters to Active Directory, and under Authorization check the Anyone can do anything option.
I'm using a Puppet module (https://forge.puppetlabs.com/rtyler/jenkins) for the automation.
Greetings,
Kenneth
If you want to modify their configuration files manually using scripts called from the CLI, then yes.
Else, I don't believe there is. At least, not a general way for all plugins. Plugins are capable of adding CLI commands, as per this documentation page:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
Extending CLI
Plugins installed on Jenkins server can add custom CLI commands. See Writing CLI commands for more details.
So, some of the plugins you're using may have specific commands to configure them from the CLI.
So as far as I know those are your options. Manual configuration through editing their config files, or hoping your plugin includes some commands in the CLI that is specific to it.
There is currently a new Plugin in development called "Configuration as Code Plugin" to provide a way for configuration of plugins using YAML: https://github.com/jenkinsci/configuration-as-code-plugin/
They are currently in an early development stage but this could help solve this kind of problem.

How do I configure global Mercurial options (like extensions) in Cloudbees Jenkins?

I have a Cloudbees Jenkins instance configured to build several Mercurial projects. I would like to configure global Mercurial options that would normally go in ~/.hgrc, such as:
[extensions]
eol =
When setting up my own standalone Jenkins instance, I normally just log in as the user running Jenkins and set up its environment.
For Cloudbees, it's not clear how I should handle this. I don't see a way to configure the Mercurial Jenkins plugin to use a specific configuration file. Even if I could do that, I'm not sure where or when to fill in that file.
Can I somehow create a ~/.hgrc that applies to my entire Cloudbees Jenkins instance? Or do I need to do this on a per-job basis? I might be able to set up HGRCPATH in a pre-build step via EnvInect, or maybe modify the project .hgrc via a script build action. However, it seems like neither of these would necessarily happen early enough in the build process to take effect when the job starts.
I feel like I'm missing something obvious. Can someone suggest the proper way to accomplish this?
Go to the system configuration page and create a new Mercurial installation. Leave Installation directory blank and set Executable to simply hg, then set whatever you need in Custom Configuration (see the inline help). Now just select this alternate installation in your project(s).

Resources