Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

label in git #2885

limor ·
Hi
I want to create tag based on different branch from the checkout branch.
In checkout step i set the branch name to develop.
Because I don't want to commit changes to develop branch - in the pre execute label step I change the branch to 'temp' branch (git checkout -b temp)
and commit the changed to this branch.

But the tag is creating by default based on the 'develop' branch, log:

16:54:34,627 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] INFO - Running step...
16:54:34,628 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] INFO - Taking snapshot of repository 'cosmo-ui'...
16:54:34,628 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] INFO - Determining head revision for repository: cosmo-ui
16:54:34,628 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - sync working directory [/opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui]...
16:54:34,628 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Detect whether repository settings have been changed ...
16:54:34,628 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Loading scm rc file ...
16:54:34,631 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Executing command: git fetch
16:54:34,632 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Command working directory: /opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui
16:54:36,470 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Executing command: git log -1 --pretty=format:%H remotes/origin/develop
16:54:36,470 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Command working directory: /opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui
16:54:36,479 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - efd61ef4458b5b9bb87bc436738bd408195b12d8
16:54:36,480 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] INFO - Creating label 'nightly' on repository 'cosmo-ui'...
16:54:36,480 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - sync working directory [/opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui]...
16:54:36,480 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Detect whether repository settings have been changed ...
16:54:36,480 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Loading scm rc file ...
16:54:36,483 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Executing command: git fetch
16:54:36,483 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Command working directory: /opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui
16:54:38,302 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Executing command: git tag -a -f -m "label created by QuickBuild" nightly efd61ef4458b5b9bb87bc436738bd408195b12d8
16:54:38,302 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Command working directory: /opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui
16:54:38,318 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Executing command: git push --tags https://opencm:******@github.com/Cloudi ... smo-ui.git
16:54:38,318 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] DEBUG - Command working directory: /opt/buildagent/workspace/root/cosmo/trunk/CI/NightlyBuild_version/cosmo-ui
16:54:41,272 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] ERROR - To https://opencm:g!ga0pencm@github.com/Cl ... smo-ui.git
16:54:41,273 [master>label_modules>tag_cloudify-ui@pc-lab131:8811] ERROR - * [new tag] nightly -> nightly

Is there a way to change it? to tell the label step the specific branch name?
  • replies 7
  • views 4428
  • stars 0
robinshen ADMIN ·
Label step will always label the branch specified in repository. To work around this, call below in pre-execute action of your label step:
groovy:
step.repository.setBranch("temp");
limor ·
Thanks it worked.
drdt ·
Robin, I found this old thread when looking for information on manipulating branches and tags in Git via the groovy scripts. But, I can't find any reference to this setBranch() method in the online contextual help. Can you help me to find it? Also, are there any other related operations, such as functions to list tags and branches in the repository?

Thank you.
robinshen ADMIN ·
setBranch() can be called but not documented, as we do not want user to call this in normal cases. As to list tags and branches, QB currently do not have that method available, and you will need to call git command directly to return that information.
drdt ·
So, rather than use this undocumented and unrecommended procedure, what can you suggest for my use case?

I am creating a 'release' promotion which is intended to:
- create a new branch based off of the build being promoted
- modify the version files on that branch to reflect the GA status of the build
- check in and push these changes
- kick off a build of the new branch

In my 'release' config (target of the promotion) I wrote a script step to create the new branch as follows:
% git branch --force --no-track ${vars.getValue("newBranch")} {repositories.get("source repository").getRevision()}

Then I set this new branch as a Pre-Execute Action in my checkout step:
step.repository.setBranch( vars.getValue( "newBranch" ) );

However, the tool checks out the actual revision as a detached head, not the branch.
robinshen ADMIN ·
To make sure the build is working on a fixed set of source code, QB always determines the commit hash of the branch at start of build, and checkout workspace on that detached commit hash. In your case you will need to call git command directly to check out the branch, make the modification and do the commit/push.
drdt ·
Thanks, I understand now. Combining this with the earlier instruction to use setBranch() before labeling, I am getting the results I need.

(Although I may move the labeling step into the triggered build job, to avoid having to use setBranch).