2
votes

I am trying to set up build with parameter, this parameter using in few build steps, it describes Jira ticket number, and comes from Jira.

Now the problem is I need to improve this build to checkout branch with this ticket number or if I don't have branch with such name - run build on master branch.

I can't use Changes tab as its fully automated process. Also I can't use git commands in build step.

Is it possible to take in build step the list of all branches from VCS and setup checkout branch in build step's script ?

used TeamCity version 9.1.1. Thank you and have a nice day.

Solution using git:

  • Set up in dependent job checkout rules to checkout on agent
  • Add build step in dependent build:

    #!/usr/bin/env bash
    
    test_branch=`git branch -a | tr -d "remotes/origin/" | grep %default_branch%`
    
    if [ -z "$test_branch" ]; then
      test_branch="master"
      echo "Switching to branch: " $test_branch
      ruby -e "puts \"##teamcity[setParameter name='default_branch' value='$test_branch']\""
    else
      echo "Switching to branch: " $test_branch
      ruby -e "puts \"##teamcity[setParameter name='default_branch' value='%default_branch%']\""
    fi
    

I'm looking for TC functionality which allow me to avoid using git. Just to check do we have such branch in +:refs/heads/*.

2
Could you clarify the build steps you're trying to set-up, including vcs checkout step? Do you get this ticket number during build process? Have you checked also whether TeamCity integration for JIRA suits your needs?Rémi Bantos
Hi Rémi, The ticket trigger build with own parameter and this build triggering dependency build with another parameters. As result we have 2 builds in build chain, I would like to set checkout branch in first build and perform all actions starts for checkout in second build. I obtaining ticket number from start. Actually we are using own solution for integration so unfortunately its doesnt suits my needs. Thank you.Kirikami
I'll try to describe more clear: We have test repository with master branch and sometimes if it was critical changes in dev repository we're creating our own test branch with same name (ticket name). Jira triggering TC job and send there branch parameter, so we are preparing environment with this dev branch, we need to check do we have such branch in test repo and if yes - checkout this to perform testing, if no - checkout branch by default.Kirikami
Why don't you let team-city test jobs run for all your branches when there are changes to existing branches or new branches with a VCS ROOT trigger?Rémi Bantos
Its not so good idea to set up trigger and run everything on changes, because all reports sending to jira and should be triggered only when ticket going to Running CI Tests status.Kirikami

2 Answers

1
votes

Semi-solution one (using git):

  1. Setup checkout on team city agent.
  2. Setup git on agents.
  3. Create build step with bash command that posted in question.
  4. Trigger build with parameter.

Problem with this solution, as I understood, that parameter couldn't be sent to VCS root if build already in queue. It could be setup only when its triggering. Also in branch column in TeamCity there won't display any personalize branches, only <default> whatever you'll run.

Solution two:

  1. Create parameter reverse.dep.*.teamcity.build.branch
  2. Trigger build with parameter.

This parameter will send for checkout for all builds in build chain. TeamCity will try to checkout branch with this parameter and if its doesn't exists it will checkout default (master) branch. As a side effect in branch column in TeamCity for all dependent builds will shows this parameter.

So for now solution #2 solved my problem.

0
votes

You could take a look at this documentation which describes how to configure properly VCS ROOT and jobs to work with feature branches (ticket branches for your use case): https://confluence.jetbrains.com/display/TCD9/Working+with+Feature+Branches