Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jfrog.hudson.util;
  import hudson.model.*;
Utility class to help extracting and assembling parameters for the a unique build identifier.

Tomer Cohen
 public class BuildUniqueIdentifierHelper {
     private static Logger debuggingLogger = Logger.getLogger(BuildUniqueIdentifierHelper.class.getName());
     private BuildUniqueIdentifierHelper() {
         // utility class
         throw new IllegalAccessError();

Get the root build which triggered the current build. The build root is considered to be the one furthest one away from the current build which has the isPassIdentifiedDownstream active, if no parent build exists, check that the current build needs an upstream identifier, if it does return it.

currentBuild The current build.
The root build with isPassIdentifiedDownstream active. Null if no upstream or non is found.
     public static AbstractBuild<?, ?> getRootBuild(AbstractBuild<?, ?> currentBuild) {
         AbstractBuild<?, ?> rootBuild = null;
         AbstractBuild<?, ?> parentBuild = getUpstreamBuild(currentBuild);
         while (parentBuild != null) {
             if (isPassIdentifiedDownstream(parentBuild)) {
                 rootBuild = parentBuild;
             parentBuild = getUpstreamBuild(parentBuild);
         if (rootBuild == null && isPassIdentifiedDownstream(currentBuild)) {
             return currentBuild;
         return rootBuild;
     private static AbstractBuild<?, ?> getUpstreamBuild(AbstractBuild<?, ?> build) {
         AbstractBuild<?, ?> upstreamBuild;
         Cause.UpstreamCause cause = ActionableHelper.getUpstreamCause(build);
         if (cause == null) {
             return null;
         AbstractProject<?, ?> upstreamProject = getProject(cause.getUpstreamProject());
         if (upstreamProject == null) {
             .fine("No project found answering for the name: " + cause.getUpstreamProject());
             return null;
         upstreamBuild = upstreamProject.getBuildByNumber(cause.getUpstreamBuild());
         if (upstreamBuild == null) {
                     "No build with name: " + upstreamProject.getName() + " and number: " + cause.getUpstreamBuild());
         return upstreamBuild;

Get a project according to its full name.

fullName The full name of the project.
The project which answers the full name.
     private static AbstractProject<?, ?> getProject(String fullName) {
         Item item = Hudson.getInstance().getItemByFullName(fullName);
         if (item != null && item instanceof AbstractProject) {
             return (AbstractProject<?, ?>) item;
         return null;

Check whether to pass the the downstream identifier according to the root build's descriptor

build The current build
True if to pass the downstream identifier to the child projects.
     public static boolean isPassIdentifiedDownstream(AbstractBuild<?, ?> build) {
         ArtifactoryRedeployPublisher publisher =
                 ActionableHelper.getPublisher(build.getProject(), ArtifactoryRedeployPublisher.class);
         if (publisher != null) {
             return publisher.isPassIdentifiedDownstream();
         ArtifactoryGradleConfigurator wrapper = ActionableHelper
         return wrapper != null && wrapper.isPassIdentifiedDownstream();

Get the identifier from the root build. which is composed of hudson.model.AbstractItem.getFullName() -hudson.model.Run.getNumber()

rootBuild The root build
The upstream identifier.
    public static String getUpstreamIdentifier(AbstractBuild<?, ?> rootBuild) {
        if (rootBuild != null) {
            AbstractProject<?, ?> rootProject = rootBuild.getProject();
            return ExtractorUtils.sanitizeBuildName(rootProject.getFullName()) + "-" + rootBuild.getNumber();
        return null;
New to GrepCode? Check out our FAQ X