With Jenkins git plugin, you have options for branch, url and credentials. How do I pass the revision (SHA1), in order to checkout a particular revision of the branch?
https://wiki.jenkins.io/display/JENKINS/Git+Plugin
Thanks.
In general, you can't. The plugin will always fetch and check out references, not commits.
Fetching specific commits by SHA1 is a relatively new feature (see Retrieve specific commit from a remote Git repository); it is not even support by all repository servers.
If you're sure that the SHA1 exists on the branch that has been fetched, then you're free to git reset the working copy in a build step. However, you'd mess with a git clone that's maintained by the git plugin -- so I recommend to take care of the entire clone/fetch/checkout step yourself, not using the git plugin.
Related
In the pipeline SCM configuration of Jenkins job builder, we have two options- lightweight checkout and shallow clone. What is the difference between these options and when do we use each option?
From the documentation:
Shallow clone.
Perform a shallow clone, so that git will not download the history of the project, saving time and disk space when you just want to access the latest version of a repository.
Lightweight checkout.
If selected, try to obtain the Pipeline script contents directly from the SCM without performing a full checkout. The advantage of this mode is its efficiency; however, you will not get any changelogs or polling based on the SCM. (If you use checkout scm during the build, this will populate the changelog and initialize polling.) Also build parameters will not be substituted into SCM configuration in this mode. Only selected SCM plugins support this mode.
To sum up:
Shallow Clone is the Git feature that lets you pull down just the latest commits, not the entire repo history. So if your project has years of history, or history from thousands of commits, you can select a particular depth to pull.
Lightweight checkout is a Jenkins capability that enables to pull a specific file from the repo, as opposed to the entire repo. So it is useful for example when fetching the Jenkinsfile from a repo because you you need only the specific file and Don't care about other SCM information.
I am looking to run the command git log --since="2 weeks ago" --stat --oneline on a git repository without requiring the clone. I am attempting to track changes made over a time period (using since) down to the specific files to commit.
The by commit is not required but, it is a nice to have. I would prefer to not clone down each repository so interfacing with the Bitbucket API would be optimal. I do have physical access to the git repositories. If required I could use the --git-dir command.
Gerrit 2.13.8-4-gb79a18cfff-dirty
I just joined a new project.
Every time I push committed code to Gerrit I need to manually feed it a list of reviewers for my ticket/issue.
Is there any way I can save this list in Gerrit or does the owner of the project need to do that ( how? )
Thanks.
A solution would be to have the reviewers plugin installed/configured in your Gerrit server. Only the Gerrit administrators can do that.
See more info about Gerrit plugins here.
See more info about the reviewers plugin here.
Yes, you can set push options in your Git configuration to automatically add reviewers for every push. For example, to add john.doe as reviewer for every change pushed from this repository:
git config --local --add push.pushOption r=john.doe
The above approach requires Git 2.16+, though. See also Can I set push-options (git push -o “…”) in git config?.
If you are still on an older Git version locally, you could pass the option via a Bash or Git alias or even use the old syntax for push options, e.g.:
alias gpr 'git push origin HEAD:refs/for/master%r=john.doe'
I am accessing the project from a Jenkins plugin, so I have access to an instance of hudson.model.Project. I know that Git is the used SCM. Is there a nice (non-hacky) way to access the last built revision?
Some details:
I am not interested in success or failure of the build, it's enough that the build was started.
"Revision": I know the Git URL and branch already, the hash of the revision that was or will be checked out for the build is needed.
I know that Git plugin sets the environment variable "GIT_COMMIT". I consider this as one of the hacky options.
If you are cloning/accessing the repository on some build step - you may want to use
COMMIT=`git rev-parse HEAD`
during the build and for example export this variable to build description or echo it into a file and archive it as a build artifact.
I've setup the Jenkins for the rails3 app to build the specs.
One can find many posts via google on how to setup the build trigger on the github push.
But what I want is to build the new remote branch pushed to Github.
e.g.
I've a repo origin/master. I cloned the repo, created a new branch, did some commits and pushed that branch to origin git push -u origin new_branch
Now I want the Jenkins to build this newly pushed branch on the origin.
If the build is successful, then Jenkins should merge it into origin/master automatically.
The Jenkins plugin has github, git plugin. But it requires to put the branch name. Instead I want to build the new_branch dynamically.
How can I setup such process?
If I remember correctly branch name is not a required entry. You need to test it, but I think if you do not fill it, Jenkins tests all new commit in the repo regardless which branch is affected.
But I recommend you do not merge automatically. You do not want that, trust me. :-)
It seems can not do that with only github and gitgub parameter plugin. If you specify branch_regex*** in Branch to build, Jenkins always build the latest commit in the bunch of branches that it saw. Must specify a branch in order Jenkins to build on the latest commit in that branch. I also see some answer with Multi Branch Pipeline but not sure how to deploy that way. There is no specific instruction at all.