How do I find Jenkinsfile properties? - jenkins

How does one go about finding the documentation on Jenkinsfile configuration options provided by Jenkins and the plugins that are installed?
For example, to set the "Do not allow concurrent builds" option, I have to set properties([disableConcurrentBuilds()]). I don't see documentation on that option anywhere except under the documentation on declarative syntax.
For plugins, I have the Github plugin installed but I don't know how to find what the option is to check "GitHub hook trigger for GITScm polling". I don't see documentation on the plugin page or github page.
Do I need to dig into the source to find these options? If so, what am I looking for in the source?

I found it under the Pipeline Syntax generator. There's a sample step for properties that allows you to check all the boxes and will generate the relevant code for you.

Related

Is there a way to automatically build tags using the Multibranch Pipeline Jenkins plugin?

After creating a Multibranch Pipeline in Jenkins I can easily tell it to poll for changes or additions of any branches and it will automatically create jobs for and build those branches. I told the Multibranch job to also discover tags, so it automatically creates jobs for each tag, which is great.
Is there a clean way for Jenkins to automatically build those tags as well, instead of me having to trigger them manually? As you can see below, the job for the tag is there, but I have to manually build it.
I would have commented with this, but I don't have enough reputation. I believe this is a duplicate of Jenkins Multi-branch pipeline doesn't schedule tag jobs. See my answer there, copied below.
In short, if you build and install the Jenkins plugin available at https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin then you can add a Build Everything strategy which will automatically build tags.
Not automatically triggering a build for discovered tags seems to be by design according to JENKINS-47496. Stephen Connolly offers an explanation and suggestion for what you might do:
Stephen Connolly added a comment - 6 days ago
Tags are not built by default (because otherwise you could have a
build storm when checking out a repository) and worse, the order tags
will be built in is unpredictable... and you might have a Jenkinsfile
that deploys to production when a tag is built.
There is an extension point in branch-api called BranchBuildStrategy
which - if implemented - will allow deciding whether to build tags.
See
https://github.com/jenkinsci/github-branch-source-plugin/pull/158#issuecomment-332773194
for starting point on how to create such an extension plugin... I
believe there is some work on one at
https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin
As #tommy-ludwig says, you need an additional plugin providing a Build Strategy ; since his original post, Stephen Connolly has published the Basic Branch Build Strategies Plugin which among others provides a strategy to build tags.
If, like me, you don't care if the tags show up on a separate tab, you just want the tags to be visible when your various branches are being built (which implies that your tags will be built), then do this:
In your multibranch pipeline's configuration, go to "Branch Sources", "Git", "Behaviors", and add "Advanced clone behaviors". By default, when you add this you will see that "Fetch tags" is checked. Voila!

Using an arbitrary plugin in Jenins 2 Pipeline scripts

Using the Snippet Generator tool in Jenkins 2, I can setup a plugin like I would within a job, and then it will generate me the Groovy I can use in my Pipeline script.
But what if the plugin I am interested in instrumenting isn't listed in the "Sample Step" drop down in the Snippet Generator? How do I determine how to create a script block to instrument the plugin I want to use?
In my case, I would like to use the "Flexible Publish" plugin within my Pipeline script.
You can't use plugins which are not compatible with pipeline generally.
Plugins need to be modified more or less to be compatible.
See https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md
To be complete you need to know that snippet generator only shows compatible plugins that declare a specific help page in plugin's code. If we take the example of docker-workflow plugin, you can see in the code that it defines a help page for DockerDSL, which means that a Snippet Generator will be available for DockerDSL step.
Therefore you should always check Jenkins plugins compatibility page (as arasio mentionned it) and not what you see in Snippet Generator.

pipeline Source for DSL

I'm starting to work on pipelines for jenkins (formerly workflow)
I'm using IntelliJ for an IDE
Is there a source of Documentation for GDSL or some way I can know what groovy is acceptable in the pipeline and what is not?
Also is there a way that I can test run the GDSL before having to check in my Jenkinsfile?
Is there a source of Documentation for GDSL
Yes, as of 1.13 you can download a GDSL schema from Snippet Generator and install it in IDEA. There are some aspects missing—for example step return types are not defined in this schema. Last I checked it also did not offer completion on, for example, known $class implementations for step; this information is available in the Snippet Generator UI and downloadable HTML reference documentation.
is there a way that I can test run the [script?] before having to check in my Jenkinsfile?
There is not currently an offline test feature; it would be tricky since everything in a Pipeline script is intended to be interacting with a live Jenkins service. (If you have other logic in there, it would be better factored out into external scripts in the language of your choice.)
As of 1.14 there is a Replay link you can use to iteratively test proposed changes before committing to Jenkinsfile, and you can use this from the CLI too.

checking diffs in jenkins

This may be unrelated to programming but does helps in it.
We use Jenkins with perforce plugin. Jenkins build is triggered by change. We can also see which files got affect in the specific changelist.
But I was curious if there is any option by which we can also see the diff between the files.
Say a changelist says : hello.cpp 2#2
So is there any way I can see the diff between 1st and 2nd version of hello.cpp file. As if there is such feature it will allow us to review the code and increase the usability.
Set up an scm browser server such as fisheye or p4web, and set up the perforce plugin to talk to it. That will provide links to the diffs for each file in the changelog.

Can jenkins the build-flow plugin trigger manual jobs?

I am currently trying to create a build pipeline. The buildflow plugin looks interesting, but I cannot find any information on whether manual steps are possible.
Does anyone know if this is possible?
Does not seem this is possible yet, but you can look at the build pipeline plugin which supports manual steps. This is an alternative plugin for implementing build pipelines that also includes nice visualizations.

Resources