![](/img/trans.png)
[英]How to programmatically get the Tags or branch name remotely from hash value using java libs for git api?
[英]How to get current branch name in Bamboo using Java Api
我已经使用以下项目创建了项目:
atlas-create-bamboo-plugin
我需要使用Java Api获取当前的分支名称。 我需要类似的东西:
@Override
public TaskResult execute(final TaskContext taskContext) throws TaskException {
final BuildLogger buildLogger = taskContext.getBuildLogger();
buildLogger.addBuildLogEntry("BranchName: " + /*Some magic*/);
return TaskResultBuilder.newBuilder(taskContext).success().build();
}
您可以将变量上下文注入任务中,并可以访问必须构建和部署的变量。 如果您熟悉Spring,它的工作原理类似于Spring bean注入。
@Scanned
public class YourTask implements CommonTaskType {
private final CustomVariableContext customVariableContext;
public YourTask(@ComponentImport CustomVariableContext customVariableContext) {
this.customVariableContext = customVariableContext;
}
@Override
public TaskResult execute(@NotNull CommonTaskContext taskContext) throws TaskException {
final TaskResultBuilder taskResultBuilder = TaskResultBuilder.newBuilder(taskContext);
final BuildLogger buildLogger = taskContext.getBuildLogger();
Map<String, String> buildVariables = customVariableContext.getVariables(taskContext.getCommonContext());
// get branch name from build variables
String branchName = buildVariables.get("planRepository.branchName");
// log all build variables to console
buildVariables.forEach((key, value) -> buildLogger.addBuildLogEntry(key + ": " + value));
return taskResultBuilder.success().build();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.