How to edit / define Jenkinsfile text within Jenkins job? - jenkins

Sometimes it is not possible (yet) to put Jenkinsfile into git repository.
I think it was possible to edit/define Jenkinsfile content just within job,
but with latest Jenkins, I cannot find such support.
Now I see only filename configuration.

OK, just be sure to select usual Pipeline project and not Multibranch pipeline

Related

Jenkins Pipeline from SCM. Can we select branch

We have our pipelines groovy scripts for Jenkins in SCM (git). I believe it currently gets the scripts from master as default.
Are we able to specify the branch we want to use for the groovy scripts?
There is a setting in the particular section but that seems to be for build branch if I understand correctly (as it allows for setting of multiple branches)
It appears that the branch option is the branch for the pipeline script.
I assume that multiple branches means you can run multiple branches of the different versions of that script. I suspect I am missing when that would be used but it does answer my original question.

Ho do I restart the jenkins pipeline with an updated JenkinsFile

I have a Jenkins project with a declarative pipeline defined in a JenkinsFile stored in a SCM. I use the "Pipeline script from SCM" option.
Sometimes if something fails I do a quick fix in the jenkins workspace and rerun the pipeline starting at a specific stage. This is working nicely.
There are cases in which I need to update the JenkinsFile and then do a 'restart at stage' with the updated Jenkins file. However, I can't find the JenkinsFile anywhere in the workspace folder. I need to know the location so I can do a quick fix and then restart the pipeline. Where is the JenkinsFile located?
See "Replay" Pipeline Runs with Modifications:
The "Replay" feature allows for quick modifications and execution of an existing Pipeline without changing the Pipeline configuration or creating a new commit.

Jenkins multibranch with Jenkinsfile in different repo

If use a multibranch pipeline in Jenkins, I want to have a build for every specific branch that is made inside my code repo. This works like a charm. But I don't want to provide a Jenkinsfile inside my code repo. Instead I want to define a different CI repo which is providing my CI pipeline scripts.
The problem is that the usual config is not containing the scm option like in the normal config.
Normal pipeline config:
Multibranch pipeline config:
Can somebody tell me how to separate the Jenkinsfile from my source code using a multibranch pipeline?
Just in case someone stunmles over the same problem,
there is a Jenkins plug-in which brings remote Jenkinsfiles for mutlibranch pipleines: https://plugins.jenkins.io/remote-file/

Jenkins Archive Downstream Multibranch Pipeline

I have a multibranch pipeline in Jenkins and need to pass the archive from the pipeline to a job it builds. The copy artifact plugin doesnt seem to support multibranch pipelines. It deletes my source project every time I save. Is there another plugin I can use to get the archive to get passed to the job? Or is there something I need to do to get this plugin working with multibranch pipeline?
The copy artifact plugin doesnt seem to support multibranch pipelines.
Copy Artifact does not care about multibranch. From its perspective, a branch project is simply a job that is in some folder. And it does support folders. You just need to use the correct syntax for the source job. Last I remember, it supports either relative (e.g., ../multibranch/master) or absolute (e.g., /organization/repo/master).

Proper configuring of Multibranch Pipeline in Jenkins

How do I properly configure a Multibranch Pipeline in Jenkins when Git is selected as branch source? I get a "Does not meet criteria" for every branch that is checked in the branch indexing log.
This Multibranch Pipeline job will create a pipeline job if your Git branch contains a Jenkinsfile.
This Jenkinsfile describe how to build the current branch (Jenkins Groovy DSL).
If your branch doesn't contain a Jenkinsfile, then you will get this "does not meet criteria" message.
More information about the Multibranch pipeline here.
Also make sure your Jenkinsfile does not have a .groovy extension
At least on Windows the casing of the Jenkinsfile is important. It has to be with an uppercase "J" and the rest lowercase.
Jenkinsfile
It appears to check the script type. The first line of "Jenkinsfile" had to be:
"#!groovy"
As Bruno Lavit points out the criteria is pretty simple.
I believe you may have an issue with your current branch.
In a clean environment, try to checkout the branch and verify that the Jenkinsfile is indeed included and that is it a valid text file.
I had a similar issue in the past where my push did not finished correctly.
I think that your jenkins plugin (Git plugin and Git Client plugin) is old.
Try to update the plugins.
I run into this when I added Jenkinsfile after I had created the Multibranch Pipeline project. The solution was to delete the project and create again :)
Still, for some Jenkins-only-know reason, it doesn't run the build on my master branch now.

Resources