We are using Hudson with git. We have a build/test server which compiles our project and then a QA server to which we need to deploy.
We want to get the current built git commit sha and use it to pull the appropriate commit for deployment on our QA server.
Unfortunately it seems that the hudon git plugin does not set the git commit sha in the environment variables (as the svn plugin does in SVN_REVISION for example). How do we get around this?
Pointer/ examples will be helpful as I am a hudson noob.
Thanks
If you need to get latest commit on a branch through the REST api, try the "/commits" call with the "until" parameter set to the branch you are interested in, and limit=1 to get the single tip commit from the branch.
"SHA" stands for Simple Hashing Algorithm. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings. A checksum uniquely identifies a commit.
Pass the commit sha1 to a predefined parameter and in Build-Execute shell run git checkout <commit> before the build process starts. Some extra work is needed to make sure the check-out goes well. Check the box This project is parameterized and then you can add predefined parameters.
I added to Post build command:
env
In log I found all environment variables. Some of them are:
BUILD_TAG=jenkins-Datagen-17 JOB_URL=http://jenkins:18080/job/Datagen/ USER=jenkins GIT_COMMIT=ce9a3c1404e8c91be604088670e93434c4253f03 JENKINS_HOME=/var/lib/jenkins JOB_NAME=Datagen BUILD_ID=2011-06-22_15-26-06 GIT_BRANCH=master EXECUTOR_NUMBER=0 NODE_LABELS=master LOGNAME=jenkins NODE_NAME=master BUILD_NUMBER=17
Jenkins Version: 2.46.2
Git Client: 2.4.5
The following GIT
variables are available by running the env
command from a shell
.
So, to inject them back into the Job's environment variables add the word env
to the Script Content
section...
Job > Configure > Build Environment > Inject environment variables to the build process > Script Content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With