Jenkins manages groovy scripts without scriptler plugin - jenkins

Since scriptler plugin has some security issues and it's not safe for use, what is the alternative plugins to manage the groovy scripts ?

Can you configure your job as a pipeline? If so, Groovy can be run inside the pipeline steps.
Also, maybe check the suggestions here:
Replacement for Jenkins Scriptler plugin?

Related

How to convert Jenkins UI to Jenkins DSL?

I need Jenkins DSL for purpose of code versioning.
I have seen that there is plugin which allows to convert jobs from groovy code to UI.
Since I have all jobs written in Jenkins UI I am wondering if there is some way to do it the other so that I will get groovy scripts from Jenkins UI jobs?
There is a plugin XML Job to Job DSL.
Each Jenkins UI job has config.xml in the file system. I have not used the plugin myself as I have converted Jenkins jobs to script manually.

How to develop groovy script effectively for Jenkins pipeline?

I'm very new to Jenkins pipeline and trying to write some Groovy scripts in pipeline. Now, I'm using declarative pipeline and writing Groovy code in Jenkins UI itself which is not helping with auto-population of methods on objects, auto-import etc.
Generally when we use IDE like eclipse, Intellij Idea for Java programming, we can see respective imports are automatically added in the code and also autosuggestion is supported.
How can I groovy code effectively for Jenkins pipeline which would save my time and help with autom-suggestion of methods, imports, compilation error etc?
I have achieved auto-import, auto-completion (and somewhat unit-testing) in IntelliJ using this setup.
The caveat is that I'm using scripted pipeline and the setup is also used for Groovy scripts for Jenkins hooks and Jenkins shared library.

Reuse jenkins pipeline or groovy script?

We have jenkins pipelines which are reused and some pipelines which use the same functions.
Now is my question: what is the right approach to reuse them.
I use a shared library but I don't know if I have to add groovy scripts or full pipelines?
The groovy scripts seem to be executed in the root instead of my jenkins workspace which is a big issue.
How are you handling this in the right way?
Using shared library is the right approach. You have to add just groovy scripts to your library and use them in your pipeline.
Have a look at an example, Pipeline and the associated library.

Configure block equivalent for Jenkins 2.0 Pipeline

For the Job DSL Plugin (https://github.com/jenkinsci/job-dsl-plugin) you can script your Jenkins jobs using this plugins DSL script with the help of their built in methods to support most plugins.
When you encounter a plugin that is not yet supported you can still use it by using a "Configure" block (https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block) that tells the plugin how to build the XML manually.
Is there an equivalent feature for the new Jenkins 2.0 pipeline (https://jenkins.io/solutions/pipeline/) to support plugins that are either not updated often or at least until the plugin author adds support?
You should have a look at new Jenkinsfile capabilities. In essence, you can now configure your entire job using the Jenkinsfile and pipeline approach.

How to invoke a plugin from Jenkins build pipeline

I have pipeline job in my Jenkins 2.x installation. In one of my steps I want to invoke a third party plugin that hasn't been updated to support pipeline jobs.
How can I invoke that plugin and have it run from my pipeline?
Use snippet generator and look for step there, and you will see a list of plugins.
It works for some plugins only, so if yours is not there you are out of luck.

Resources