Skip to content
Permalink
Browse files

HAP-313 - build.root should be BUILD_TAG taken from env vars

  • Loading branch information...
Shay Yaakov
Shay Yaakov committed May 21, 2012
1 parent 7d085cc commit 840d357458d93109b4cfddc41e287c8d60d4b521
@@ -166,13 +166,10 @@ private void deployArtifact(MavenBuild mavenBuild, MavenArtifact mavenArtifact)
.addProperty("build.name", ExtractorUtils.sanitizeBuildName(mavenModuleSetBuild.getParent().getFullName()))
.addProperty("build.number", mavenModuleSetBuild.getNumber() + "")
.addProperty("build.timestamp", mavenBuild.getTimestamp().getTime().getTime() + "");
if (downstreamIdentifier && ActionableHelper.getUpstreamCause(mavenBuild) == null) {
debuggingLogger.fine("Adding unique identifier to artifact:" + builder);
BuildUniqueIdentifierHelper.addUniqueBuildIdentifier(builder, env);
}
if (rootBuild != null) {
debuggingLogger.fine("Adding build.root from root build");
BuildUniqueIdentifierHelper.addUpstreamIdentifier(builder, rootBuild);

String identifier = BuildUniqueIdentifierHelper.getUpstreamIdentifier(rootBuild);
if (StringUtils.isNotBlank(identifier)) {
builder.addProperty(BuildInfoFields.BUILD_ROOT, identifier);
}

Cause.UpstreamCause parent = ActionableHelper.getUpstreamCause(mavenModuleSetBuild);
@@ -1,15 +1,10 @@
package org.jfrog.hudson.util;

import hudson.Util;
import hudson.model.*;
import org.apache.commons.lang.StringUtils;
import org.jfrog.build.api.BuildInfoFields;
import org.jfrog.build.client.DeployDetails;
import org.jfrog.hudson.ArtifactoryRedeployPublisher;
import org.jfrog.hudson.action.ActionableHelper;
import org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator;

import java.util.Map;
import java.util.logging.Logger;


@@ -21,40 +16,11 @@
public class BuildUniqueIdentifierHelper {
private static Logger debuggingLogger = Logger.getLogger(BuildUniqueIdentifierHelper.class.getName());

private static final String BUILD_ID_PROPERTY = "${JOB_NAME}-${BUILD_NUMBER}";

private BuildUniqueIdentifierHelper() {
// utility class
throw new IllegalAccessError();
}

/**
* Add the unique build identifier as a matrix params to all artifacts that are being deployed as part of the build.
* The key of the matrix param is {@link org.jfrog.build.api.ArtifactoryResolutionProperties#ARTIFACTORY_BUILD_ROOT_MATRIX_PARAM_KEY}
* and the identifier value is the interpolated value of {@link BuildUniqueIdentifierHelper#BUILD_ID_PROPERTY}
*
* @param builder The deploy details builder
* @param env The map used for interpolation of the value.
*/
public static void addUniqueBuildIdentifier(DeployDetails.Builder builder, Map<String, String> env) {
String identifier = getUniqueBuildIdentifier(env);
builder.addProperty(BuildInfoFields.BUILD_ROOT, identifier);
}

/**
* Add the unique identifier as a matrix param with key {@link org.jfrog.build.api.ArtifactoryResolutionProperties#ARTIFACTORY_BUILD_ROOT_MATRIX_PARAM_KEY}
* The value of this parameters is taken from the upstream build.
*
* @param builder The deploy details builder.
* @param build The upstream build from where to find the value of the property from.
*/
public static void addUpstreamIdentifier(DeployDetails.Builder builder, AbstractBuild<?, ?> build) {
String identifier = getUpstreamIdentifier(build);
if (StringUtils.isNotBlank(identifier)) {
builder.addProperty(BuildInfoFields.BUILD_ROOT, identifier);
}
}

/**
* 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
@@ -130,8 +96,8 @@ public static boolean isPassIdentifiedDownstream(AbstractBuild<?, ?> build) {
}

/**
* Get the identifier from the <b>root</b> build. which is composed of {@link hudson.model.AbstractItem#getName()}-{@link
* hudson.model.Run#getNumber()}
* Get the identifier from the <b>root</b> build. which is composed of {@link hudson.model.AbstractProject#getFullName()}
* -{@link hudson.model.Run#getNumber()}
*
* @param rootBuild The root build
* @return The upstream identifier.
@@ -140,11 +106,4 @@ public static String getUpstreamIdentifier(AbstractBuild<?, ?> rootBuild) {
AbstractProject<?, ?> rootProject = rootBuild.getProject();
return ExtractorUtils.sanitizeBuildName(rootProject.getFullName()) + "-" + rootBuild.getNumber();
}

/**
* @return The interpolated value of {@link BuildUniqueIdentifierHelper#BUILD_ID_PROPERTY} by the environment map.
*/
public static String getUniqueBuildIdentifier(Map<String, String> env) {
return Util.replaceMacro(BUILD_ID_PROPERTY, env);
}
}

0 comments on commit 840d357

Please sign in to comment.
You can’t perform that action at this time.