Tell Jenkins I want to build a specific commit in a pipeline project - jenkins

I have a pipeline project added to Jenkins. I would like to tell Jenkins to build a specific commit in this project by using a REST query.
The project is configured as Jenkinsfile pipeline project. I would like Jenkins to get the Jenkinsfile from this specific commit I've selected, and then the pipeline script would checkout the code and perform the build.
My problem is that I can't force Jenkins to take Jenkinsfile from my selected commit. I can configure it so it'll get Jenkinsfile from master or any other branch, but I don't know how to parametrize the place where I want Jenkins to take Jenkinsfile from.
I.e. when building commit foo, I want Jenkins to checkout the repository I've provided, switch to commit foo and use Jenkinsfile from this commit. Next build job would want to use Jenkins to build commit bar; in such case Jenkins would clone the repo, switch to the bar commit, and start the Jenkinsfile from the bar commit.
Is this action supported by Jenkins?

Duck debugging in action.
My problem was resolved by making sure the "lightweight checkout" in the Git repository settings pane was un-checked. A bug in Jenkins?

Related

List Git Branches on Jenkins after the pipeline build

Currently i'm using in my jenkins pipeline the List Git Branches system, and its working very well, when i'm gonna build the pipeline, i choose the branch that is automatic pulled from git repository that i specify in the pipeline configs. But i have a problem, i need to make a new pipeline model that the user gonna choose the git repository link with a jenkins choise parameter before the build starts and when the build starts, the branchs gonna be pulled and displayed to choise, so well, i'm needing a way to pause the pipeline build to user choise the especified branch and after that the proccess continues normally.

Jenkins being run on all branches in repo instead of only the branch changed

I am pretty new to Jenkins, and when I make a pull request, the Github webhook triggers a rebuild on all branches in the repo. However, I only want the branch associated with the pull request to be built. I suspect that all branches are built due to nothing specified in the "Branch specifier."
Is there a way to specify to build only the branch the pull request was made to?
Thanks!
To resolve your issue try to use multibranch pipeline job or use filter in simple pipeline job.
To use multibranch pipeline job you need to install Pipeline: Multibranch plugin.
Pipeline job example
In simple pipeline job choose "Build when a change is pushed to GitLab" in "Build trigger" section -> Advanced -> Filter branches by name

Jenkins pipeline build branch triger

I have gitlab with commit hook to Jenkins. The hook is triggered on any commit in any branch. Jenkins has three branches to build.
And I have a problem. If I create any other branch and push it, the hook will trigger the Jenkins and Jenkins will build a branch (master, develop or hotfix) with the newest commit. How can I forbid the build for all other branches except the specified three? I know about when, I need to cancel the build, not just one stage
I found an item in the submenu that is responsible for which branches are used to activate the build.

When Multibranch pipeline when job is trigged, what is stored in Jenkins workspace?

I am not sure if I am asking the question in right way.
When I am triggering the multi branch pipeline job and I do "checkout scm" in Jenkinsfile, does it checkout the pull request or Master + pull request?
It depends of your settings.
As I remember, multibranch pipeline builds pull requests in separated view and it can build as PR source branch and result of PR. It cloned your repo, checkouts target branch, merges source branch into it and runs your stages.
If you look at the logs you will see that it checks out the hash of the commit
example: git checkout 1fb651dfdcbea276627de0247bbf5047840cae4c
As for workspace, if you log in to the Jenkins machine where this is running you will see that each branch has a separated workspace. Here you will find the source code of the checked out branch. The separated workspace ensures that there is no conflict when working with multiple concurrent branch builds.

Update manually commit and branch attributes from jenkins pipeline blueocean

We are using jenkins for manual triggered jobs to deploy some code.
Jenkinsfile describing our pipeline is located in a jenkinsfile dedicated repo (not in deployed code repo).
We are using declarative pipeline syntax and shared libraries in our jenkinsfiles.
In BlueOcean interface there are 2 interesting attributes (branch and commit) automatically filled when using plugins to trigger pipelines (like github organization).
I'm searching a way to set/update these 2 attributes manually from within the pipeline code for our manual pipelines.
Job description and name can be easily updated using something like :
stage('Set pipeline description'){
steps {
script {
currentBuild.description = "Deploying branch ${branch} on ${targetEnv}"
}
}
}
But I didn't find anywhere how to update branch or commit values.
Did anybody try this ?
This issue is reported as bug (see link).
"We are using GitLab web hooks to trigger Jenkins Pipeline project builds on new commit push to GitLab. Build is triggered, CI commit status report is being sent back to gitlab, but can't see branch and commit field in Header-details element."
Please vote on this issue on Jenkins CI website if you want for the issue to be resolved sooner.

Resources