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?