What does this variable mean in CircleCI
CIRCLE_SHA1
The SHA1 of the commit being tested.
How can i set the value for this?
This is the SHA1 hash of the commit as created by Git. You can see examples of these hashes for each commit when you run git log.
You don't set the value for this. It's created by CircleCI to show you the commit that CircleCI is currently building.
Related
migrating to the GitHub action from Travis CI,
there is a line
'git diff --name-only "$TRAVIS_COMMIT_RANGE"'
but it is for Travis and while running on GitHub action not getting the value of this variable "$TRAVIS_COMMIT_RANGE"
what should we use instead of this variable to get the value
COMMIT_RANGE: ${{ github.event.before}}...${{ github.event.after}}
In github.event we have all the details so, we can use before and after to get the "$COMMIT_RANGE" same as in travis "$TRAVIS_COMMIT_RANGE" variable
I have an issue with gitlab, gitlab-ci and fastlane. In fastlane, I am using :
def increment_build_and_commit
incrementBuildNumber()
commit_version_bump(message: 'build number bump [skip ci]')
push_to_git_remote(
remote: 'origin_rw',
remote_branch: ENV['CI_COMMIT_BRANCH']
)
end
So I want to increase build number and commit. So it does the job with:
incrementBuildNumber(),
commit_version_bump(message: 'build number bump [skip ci]')
But when running, it fails at push_to_git_remote
[!] Exit status of command 'git push origin_rw HEAD:HEAD --tags
--set-upstream' was 1 instead of 0. error: The destination you provided is not a full refname (i.e., starting with "refs/"). We
tried to guess what you meant by:
Looking for a ref that matches 'HEAD' on the remote side.
Checking if the being pushed ('HEAD') is a ref in "refs/{heads,tags}/". If so we add a corresponding
refs/{heads,tags}/ prefix on the remote side. Neither worked, so we
gave up. You must fully qualify the ref. hint: The part of the
refspec is a commit object. hint: Did you mean to create a new branch
by pushing to hint: 'HEAD:refs/heads/HEAD'? error: failed to push
some refs to '**********.git'
Some of you have any clues what to do and how to solve this problem? As I am going to be a google machine on that, but unfortunetly can't find the solution.
Thanks in advance!!
This happens because gitlab-ci checkouts git commit instead of git branch and you enter detached HEAD state.
There are few ways to get around this:
1) Use CI provided value. For GitLab I would recommend using CI_PIPELINE_IID. Downside is that you cannot control it and if you migrate your project to other repository it will start from 1 again.
2) Checkout git branch before making commit. Downside is that if other developer pushes to the same branch, your pipeline will continue with wrong source code.
3) Commit version number bump manually.
i need to build a job in Jenkins, to get latest git commit message every time a commit is done and to store it in a variable.Can anyone suggest a plugin or a way to do this?
Use command line and get the commit message that you want and create a file as key value and inject the variable:
Step by step:
Install git plugin, EnvInject Plugin.
Get the last git commit by the command git log -p -1 and parse from that what you need.
Create a file as key value for example LAST_COMMIT_ID=cab123gfbdak
Use the envInject as file (this load the key value file that you created to Jenkins as Jenkins variable).
Good luck.
Need to analyze a currentBuild.changeSets. Full answer in another stackoverflow topic. Also, you can read a doc here
I am trying to access github env.CHANGE_AUTHOR environment variable from groovy script in jenkins multibranch pipeline.
While some of the environment variables are giving correct output (for example env.JOB_NAME,env.BRANCH_NAME), others like env.CHANGE_AUTHOR_DISPLAY_NAME ,env.CHANGE_AUTHOR_EMAIL are giving null values.
Has anybody come across this issue before? What can be the problem?
I've just tested with the github org plugin which uses the multi branch plugin, created a PR and the CI job it does has those env vars present. Using a Jenkinsfile:
node {
echo "${env.getEnvironment()}"
}
In my Jenkins PR build console I see amongst others:
CHANGE_AUTHOR:rawlingsj, CHANGE_AUTHOR_DISPLAY_NAME:James Rawlings, CHANGE_AUTHOR_EMAIL:rawlingsj80#gmail.com, CHANGE_ID:1, CHANGE_TARGET:master, CHANGE_TITLE:test msg, CHANGE_URL:https://github.com/rawlingsj/multi-branch-test/pull/1
Just a wild guess.. do you have your git config user.name and git config user.email set on the commit in the PR? If so it's worth mentioning which version of the multi branch plugin you're using and upgrade to the latest if its old.
I think this is related to an existing bug where the git environment variables are always null:
https://issues.jenkins-ci.org/browse/JENKINS-36436
It looks like it was very recently fixed in this PR:
https://github.com/jenkinsci/git-plugin/pull/492
I know there is a http deploy hook I can use but unfortunately it does not submit the branch name, here is what it does submit:
{"head"=>"7021419", "app"=>"appname", "git_log"=>"commit message", "action"=>"home", "url"=>"site url", "prev_head"=>"1d844b0", "controller"=>"account_sessions", "user"=>"heroku#user.com", "head_long"=>"7031429230228988d8f3312fa9e74d77b6c1bc14"}
I tried using the head or head_long to figure out the branch name with:
git branch --contains SHA
Which worked, but it is not 100% accurate as the same SHA could be in multiple branches. Same can be said about:
git reflog show --all | grep 7021419
I am pretty sure it is impossible to get the current branch name from within the deployed app as the branch deployed to Heroku is always the "master" branch. I was hoping I can send the deploy callback hook to another server and store the deployment record somewhere.
1. Detecting only
If it's just about heads, use
git rev-list --no-walk --glob=refs/heads
with a bit of --format and grep logic tacked on
2. Tracking locally
The simplest way would be using a tag.
Push the tag like a normal branch:
git push herokuremote tagname:publicbranchname
Unfortunately, that would just push the tag, not a branch... ; read on for alternative
(note I don't know/use heroku, so I don't know the naming conventions, sorry)
3. Symbolic branch reference
If you don't mind using a bit of plumbing, you can name a local ref as the one deployed. You can have a symbolic ref for the purpose:
git update-ref -m "deployed release candidate" --no-deref refs/heads/deployed master
If the same SHA is in multiple branches, they are effectively the same branch (at least at that point in time). If you're sure that SHA is the last commit of a branch, you can find it in .git/refs/heads/* where * is a list of files whose names correspond to branch names and contents are the SHAs.
It seems like you might be able to solve this recording problem by not using their API. Wrapping your deploy script (or Heroku's deploy binary, or a post-push hook) should give you the flexibility you need to notify a different service for record keeping.