Adding Global passwords to Jenkins using groovy - jenkins

Im provisioning my Jenkins using groovy, I need to configure Jenkins.
To be specific Manage Jenkins - configure system
Like Global password, Gitlab configuration and Project configuration.
I'm new to groovy I have very less knowledge on groovy.
It would be really helpful if anyone can share groovy script to configure Jenkins?!

this is a great idea , 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.
if you have specific question , let me know
Thanks , Mor

Related

How to configure Fortify plugin using 'Jenkins Configuration As Code' Jenkins plugin (JCASC)?

I'm setting up a new Jenkins master server and configuring it using the Jenkins Configuration as code (JCASC) plugin.
https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/README.md
I've configured most plugins with JCASC, based on documentation and examples inside the project, but I can't find the syntax for configuring plugin 'Fortify Jenkins Plugin' version 18.10.
I need to set these properties:
URL of the remote Fortify server, authentication token (generated on the fortify server) and which template to use.
Can anyone assist with an example or syntax for the yml file used by the JCASC plugin for Fortify plugin?
I don't know if fortify-plugin is compatible with JCasC, it might be or it might need some modifications. That said, if it is compatible, then the configuration export should work for it.
So, spin up a Jenkins instance, install the plugin, configure whatever you want in the Jenkins UI and then go to the CasC page and use the configuration export. That should give you a JCasC file containing your setup.
Alternatively, you can try the JCasC Schema experimental feature. It's a JSON schema generated by Jenkins that you can use in your YAML editor for autocompletion. More information here.
we have just released an update of the Fortify plugin with support for JCasC. Keep in mind, versions of the plugin prior to v21.1.36 were unable to support it, we had to make changes to make it happen.
You can find official documentation on how to use our configuration elements here. There's one correction to the documentation, though. Our top level configuration element is called fortifyPlugin instead of fortify mentioned in the documentation. It is going to be corrected in the next documentation update.
Here's a sample configuration for your quick reference:
unclassified:
fortifyPlugin:
url: "https://qa-plg-ssc3.prgqa.hpecorp.net:8443/ssc"
token: "3ab8c774-0850-483b-8be6-2907722a81d8"
proxyConfig:
proxyUrl: "web-proxy.us.softwaregrp.net:8080"
projectTemplate: "Prioritized High Risk Issue Template"
connectTimeout: "10"
readTimeout: "20"
writeTimeout: "10"
breakdownPageSize: "50"
ctrlToken: "5176d380-26ac-430f-95d7-0a2272cf3297"

Jenkins Pipeline - Call functions in shared jar

So here is my project setup
A separate groovy project
Multiple pipelines
All the pipeline scripts refer to the shared groovy project. I went through the shared libraries and all of the needs to be registered in Jenkins global configuration.
Is there any way to do without it? I tried using Grab but ended up with the error
java.lang.RuntimeException: No suitable ClassLoader found for grab
Firstly for Grab to work your Jenkins needs to have access to the internet.
Shared Libraries are definitely the way to go here.
Like many things the secret sauce is in the syntax.

Jenkins Email-ext plugin is no longer visible in the project's post build options

Does any one have any idea what could have happened to Jenkins Email-ext? We have had this plugin working just fine for over two years and all of sudden our entire configs for this plugin have disappeared from all of our projects. We tried to uninstall and re-install the plugin but that didn't make any difference.
Once you install this plugin there should be a checkbox under "Post-build Actions" section in the projects config page to enable it but this option is not shown any longer here. Any idea?
Thanks!
This issue was fixed by following the below steps:
Uninstall email-ext plugin from Jenkins
Stop Jenkins services. (Run > Services.msc) find Jenkins and stop it
Go to Jenkins home (base folder) > Plugins and remove any instances of email-ext plugin (e.g. C:\Program Files (x86)\Jenkins\plugins)
Restart Jenkins
Install email-ext plugin again
And now everything should be working OK again!
if you haven't upgraded your jenkins then the issue might be a different one , just to make sure email configuration section has completely removed from your job , check the config.xml of your jenkins job for the keyword [email-ext].
how to check job's config.xml from GUI ?
simple click on configure link of your job you will be redirected to something like below
http://yourserver/job/jobname/configure
now change the last part of url [configure to config.xml] resulting in something like below
http://yourserver/job/jobname/config.xml
now search for keywords like email and email-ext , if you did not find anything then email-ext plugin is not functioning or its has completely removed the email configuration from your job , if you find an entry , do a uninstall /install and then try a restart of jenkins might resolve your problem , or else you can try the option of reloading configuration from disk.

Jenkins environment variables

I am a novice to Jenkins administration, trying to help a friend set up Jenkins for his startup.
I know there are plugins in Jenkins but not quite familiar on how to achieve his requirements.
He has a spring application which uses dispatcher.xml to reference jdbc.properties (one for each environment eg: jdbc_dev, jdbc_test, jdbc_prod.
How do I setup environment variables in Jenkins so the respective jdbc.properties is picked when the war file is built ?
I think following plugins will help your friend a lot.
1) EnvInject Plugin:- To inject environment variables depending on the requirements.
2) Role strategy :- To manage authorization and permissions of various users. For eg: Admin,Tester,Developer,guest.
For more info on configuration on this plugin read this Answer
3) JobConfigHistory Plugin:- To revert changes if you screw anything.
Hope it helps.
See Parameterized Build:
Sometimes, it is useful/necessary to have your builds take several "parameters".
...
The parameters are available as environment parameters variables. So e.g. a shell ($FOO, %FOO%) or Ant (${env.FOO}) can access these values.
[Corrections by me.]
See also the Matrix Project Plugin:
A multi-configuration project is useful for instances where your builds will make many similar build steps, and you would otherwise be duplicating steps.

How to edit a file with environment variables in jenkins

I'm bit new to jenkins. What I want is to edit config files with environment variables of jenkins. I tried ant scripts, Nant plugin but all ended up with errors. If anyone knows something about this please help. For example lets think we want to replace word "hello" in C:\files\test.txt to "bye". word "bye" should be taken from a environment variable of jenkins. Thanks
Best is to utilize Jenkins EnvInject plugin. With that you can have a build step to manipulate/generate your properties, and then you can add another build step to load these properties into project environment variables.
See this stackoverflow question for a more detailed example.

Resources