Where is the documentation for git scriptPath if creating a job DSL pipeline? - jenkins

E.g. if you were creating the Job DSL for a pipeline such as mentioned here Defining jenkinsfile script path when creating pipeline where is the documentation for scriptPath?
I don't see anything here: https://plugins.jenkins.io/git/

as described in the comment, the script path is the relative location of your Jenkinsfile in the git repository.
here you can find information about Jenkinsfile:
https://www.jenkins.io/doc/book/pipeline/jenkinsfile/
here you can find information about syntax:
https://www.jenkins.io/doc/book/pipeline/syntax/
in addition in your Jenkins gui once created a pipeline item, configure it and you can find the link to "Pipeline Syntax" that help you to generate a script.

Related

Jenkins Multibranch Pipeline: script / jenkinsfile as svn external

I have a multibranch pipeline in Jenkins. I want to include my script file (jenkinsfile) as svn file external into my development branches to organize the script centralized for all branches. Unfortunately the scan of the multibranch pipeline isn't able to find the script file as it is only looking inside the declared branch and not in the included svn external locations.
Has anyone an idea how can I fix this?
Below is an example of my svn structure, job config and further information.
SVN:
root/
scripts/
jenkinsfile
code/
version1/
branchX/
...
version11/
branchY/
...
SVN external property for branchX, branchY, etc.
Local path: jenkinsfile
URL: ^/scripts/jenkinsfile
Revision Peg: 12345
Multibranch job configuration:
Subversion
Project Repository Base: http://.../root/code/
Include branches: version1/branchX, version11/branchY
Build configuration
Mode: by Jenkinsfile
Script path: jenkinsfile
Log message of scan in multibranch pipeline:
...
Checking candidate branch /code/version1/branchX#HEAD
‘jenkinsfile’ not found
Does not meet criteria
...
I already tried to disable the lightweight checkout of the subversion scm plugin according to this advice:
Multibranch pipeline with jenkinsfile in svn:external
(I've added -Djenkins.scm.impl.subversion.SubversionSCMFileSystem.disable=true under <service><arguments>... in jenkins.xml)
But jenkins is still not able to find the script. And in fact if I put my script directly in e.g. branchX the disabled lightweight checkout leads to a double checkout into my workspace (first one to read the script file and second one as it's my first stage in the script itself).
Maybe my whole setup is wrong too or not the ideal way of doing?
I would be pleased about your help and tips. Thanks and Greetings!
If you are working on a linux or bsd(osx) system, you could create a hard-link from root/scripts/jenkinsfile to root/code/version#/branchX/jenkinsfile for each active branch
That way, each branch will have its own jenkinsfile available locally, enabling you to use the lightweight checkout, and any change you introduce to the jenkinsfile in any location will be available to all other branches (the file system will keep a single copy of the file, regardless of being accessible form many different locations).
The bash command to create such link will be
ln root/scripts/jenkinsfile root/code/version#/branchX/jenkinsfile
You will need to remember to create a new link each time a branch is created, or automate that using hooks

How to compile Jenkins Pipeline Groovy locally?

Does anyone have the magic maven/gradle invocation to compile a set of jenkins pipeline DSL groovy files?
Groovy is not compiled (like C#), it is interpreted.
Depending on exactly what you are trying to test potential options are:
Jenkins Groovy Script Console under Manage Jenkins. Note: You will need to be an Admin to be able to access this.
Pipeline Syntax Generator. It is improving. Go to a build of Pipeline job and in the LHS menu you will see a 'Pipeline Syntax' link. Some items require you to first select Pipeline: Steps from the first dropdown.

Jenkins pipeline run gradle tasks within sshagent

I'm creating a jenkins pipeline which utilizes a build.gradle script to build the project.
One of the first things gradle does is check out some git repos, I need to run this with ssh, so I thought I could wrap the code in sshagent like this:
sshagent(['c6f7cd1b-9bb3-4b33-9db0-cbd1f62cd0ba']){
sh 'git clone git#Repo.git'
}
the Id is mapped to a global jenkins credential with the private key in it, I also use it in another pipeline to tag a repo and push it to master, using the same credentialId.
However I get following output when trying to run the pipeline:
FATAL: [ssh-agent] Could not find specified credentials
I have no idea why I get this, when I'm using a copy paste from the other pipeline.
Anyone who can point me towards the right direction?
Thx

How to extract Jenkinsfile by a custom script?

I've created a Jenkins job of type "Pipeline", and used an inline pipeline script. Now I'd like to put the script under version control and use the "Pipeline script from SCM" option (I think, I don't have to describe the merits of this).
However, our version control system (CA SCM) is not well supported in Jenkins: I couldn't make the plugin to check out anything.
We do have, however, some scripts for working with CA SCM that allow to check out things reliably.
So, my question is: Is it possible (and how) to have the Jenkinsfile under version control, do the check out for it by a custom script (e.g. using a .bat command) and then have the pipeline executed as if the Jenkinsfile had been extracted by the "Pipeline script from SCM" option?
I.e., as I understand it, I need a command in the pipeline plugin to execute a given Jenkinsfile.
You could try to use the feature "Prepare an environment for the build" from the "Environment Injector Plugin" (https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin) and provide a script file (or inlined content) to execute.

Upload files to userContent of jenkins server

I have a multi-branch pipeline job from which I would like to upload a file to the Jenkins userContent location using a Groovy script. I tried the job-dsl-plugin to use userContent method, but it throws the error shown below:
java.lang.NoSuchMethodError: No such DSL method 'userContent' found among steps
Reference: https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands
Do I need to configure anything in order to upload a file to userContent? Is there any other way to upload a file to the userContent location?
You can not simply mix Pipeline DSL and Job DSL. See Use Job DSL in Pipeline scripts for instructions on using the Job DSL build step as a Pipeline step.
node {
jobDsl scriptText: 'userContent("test.txt", new ByteArrayInputStream("test".bytes))'
}

Resources