Jenkins setup from code - jenkins

Is there a way to setup a Jenkins from code (eg. AWS userscript) doing
configurations like setting up a user, configuring GIT and slack
plugins?
So far I can install the Jenkins and even add plugins but I'm not able to configure it. This is only possible doing manually afterwards.
I heard about the Jenkins-CLI but don't know how to obtain it, if I just setup the system? Is it also enough to configure the system as I would access it via the UI?

Related

Deploying configuration via Jenkinsfile to unknown amount of servers

We're setting up multiple more or less static servers in AWS. These are primarily configured via Ansible and that's also the ultimate source of truth when it comes to their existence, grouping, host names and IPs. But then there's Jenkins deploying configuration files to these servers based on new commits added to a git repository.
I'm having an issue with listing the target servers directly in a Jenkinsfile. How shall I proceed? Which are the most common ways of dealing with this?
I understand this is mostly an opinion based topic. But maybe there's a particular Jenkins feature which I don't know about...?
Thank you.
This is very subjective. Following are a few ways to do this.
Store the details somewhere accessible after the Ansible step. Possibly commit to a Github repo and retrieve these details within the Jenkins Job.
Using AWS APIs/CLI to retrieve server details. You can either set up AWS CLI in Jenkins Agent or use something like AWS Step Plugin.
Do an API call to Jenkins after the Ansible script is executed and update the server details in the Job itself.

How i can setup my Jenkins that can be used in different machines?

How i can setup my Jenkins that can be used in different machines? i want a jenkin to be setup and any one can hit the URL with IP and login with valid credentials.
The main aim is not to configure jenkins on every colleagues system and they can access my jenkins just through an URL.
You can install one instance of Jenkins in a dedicated server, tune it, secure it and create the Jobs. After it you can share the IP/Host and the user & password to your colleagues and they can access to Jenkins.
I recommend you to check the installation manual: https://jenkins.io/doc/book/installing/

global tool configurations in jenkins through cli?

Is there a way to add global tool configurations for artifactory and aws in jenkins through cli?
I'm trying to write chef cookbook for automating creation of Jenkins job, but I don't know how to add credentials for tools.
Credentials don't depend on the tools which will use them.
You can register credentials in general through the JENKINS Credentials Plugin API: see for instance
How to create jenkins credentials via the REST API? (similar to jenkins_api_client issue 162)
update Jenkins credentials by script
You can then use those credentials in association with a Jenkins Job.
Your question is twofold.
Credentials
The Jenkins chef cookbook offers a jenkins_credentials resource, which allows you to pipe credentials (using Jenkins API internally) into your Jenkins instance.
Global Tool Configuration
You can use the jenkins_script resource of the same cookbook to execute any Groovy script. This allows you to configure your Jenkins instance. You now just have to figure out exactly, what the code is to, e.g., select the previously defined credentials. But the code looks similarly to the example given in the cookbook's README.

Artifactory Jenkins Plugin

I'm using the Artifactory plugin for my Java projects and also for some RPMs that I'm building (c++).
Some of Jenkins jobs are pushing artifacts using the REST API via CURL.
Is there any way via the plugin and/or via REST, to prevent overriding of an existing artifact (sometimes our versioning mechanism is not working properly, so I need to prevent this scenario)?
You should leverage the permissions for that. In Artifactory "add" and "override" are different permissions. Just prevent the user which pushes from Jenkins from overriding, and you're done.

Configuring Jenkins plugins with Puppet

I'm using the rtyler/jenkins Puppet module to deploy my Jenkins instance. One thing I can't seem to find documentation on is how to use Puppet to configure the Jenkins plugins once I've installed them. Can someone point me to some documentation and/or write a quick example? Thanks.
the module he provides is only for managing/configuring jenkins and managing plugins. All plugins are vastly different, there is no possibility his scripts would be able to manage the wide breadth of jenkins plugins out there. You would want to try to capture that using jenkins backups or by looking into how each module allows configuration.
For anyone interested in how to pull this off, I'm using the Jenkins SCM plugin available here: https://wiki.jenkins-ci.org/display/JENKINS/SCM+Sync+configuration+plugin
This requires manually setting up Jenkins and having the plugin sync all the configuration settings to a repository. All future Jenkins instances provisioned by Puppet will need to have all the necessary plugins installed, but the SCM plugin will automatically download all the necessary settings. However, do note that some of the plugins will require you to manually add includes into the SCM to begin tracking them: https://wiki.jenkins-ci.org/display/JENKINS/SCM+Sync+Config+shared+additionnal+includes

Resources