You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I already tried by using jgit:
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Ref;
import java.io.File;
import java.io.IOException;
Repository repository = FileRepositoryBuilder.create(new File("../.git"));
currentBranch = repository.getBranch();
System.out.println("Current branch: " + currentBranch);
This unfortunately throws an access denied error.
[ERROR] Failed to execute goal com.atlassian.bamboo:bamboo-specs-runner:6.9.2:run (default-cli) on project bamboo-specs-generator: Execution default-cli of goal com.atlassian.bamboo:bamboo-specs-runner:6.9.2:run failed: access denied ("java.lang.RuntimePermission" "getenv.GIT_OBJECT_DIRECTORY") -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.atlassian.bamboo:bamboo-specs-runner:6.9.2:run (default-cli) on project bamboo-specs-generator: Execution default-cli of goal com.atlassian.bamboo:bamboo-specs-runner:6.9.2:run failed: access denied ("java.lang.RuntimePermission" "getenv.GIT_OBJECT_DIRECTORY")
Or maybe someone who knows how to solve the access denied exception?
Did you figure this out? We are running into a similar problem reading environment variables in Java Specs file.
In the path where the bamboo specs is executed contains the path name (a bit encoded, e.g. / is encoded as _2F).
So an ugly solution would be to use the path to obtain the branch name (note: no decoding done in this example). Also note that this can break at any bamboo release, since it is not something that is specified.
public static final String REPOSITORY_PATH_PREFIX = "repository-";
public static String GetBranch()
{
String path = Paths.get(".").toAbsolutePath().normalize().toString();
for (String element : path.split("/"))
{
if (element.startsWith(REPOSITORY_PATH_PREFIX))
{
return element.split("-", 3)[2].trim();
}
}
return "unknown";
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That was a good hint. I have it sorta working. It cleanly identifies if I am in develop branch, but I am stumbling on the master branch. Its probably in my setup of my test environment, but for anyone else looking at this, this looks very promising.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.