Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions api/src/main/java/org/jfrog/artifactory/client/Builds.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.jfrog.artifactory.client;

import org.jfrog.artifactory.client.model.AllBuilds;
import org.jfrog.artifactory.client.model.BuildPromotionRequest;
import org.jfrog.artifactory.client.model.BuildPromotionResponse;
import org.jfrog.artifactory.client.model.BuildRuns;
import org.jfrog.build.api.Build;

import java.io.IOException;

Expand All @@ -12,4 +15,44 @@ public interface Builds {
AllBuilds getAllBuilds() throws IOException;

BuildRuns getBuildRuns(String buildName) throws IOException;

/**
* Upload a build to Artifactory using the official build-info API
*
* @param build the build info from org.jfrog.build.api.Build
* @throws IOException if the upload fails
*/
void uploadBuild(Build build) throws IOException;

/**
* Upload a build to Artifactory with a project parameter using the official build-info API
*
* @param build the build info from org.jfrog.build.api.Build
* @param project the project name to limit the build to
* @throws IOException if the upload fails
*/
void uploadBuild(Build build, String project) throws IOException;

/**
* Promote a build in Artifactory
*
* @param buildName the name of the build to promote
* @param buildNumber the number of the build to promote
* @param promotionRequest the promotion request details
* @return the promotion response with messages
* @throws IOException if the promotion fails
*/
BuildPromotionResponse promoteBuild(String buildName, String buildNumber, BuildPromotionRequest promotionRequest) throws IOException;

/**
* Promote a build in Artifactory with a project parameter
*
* @param buildName the name of the build to promote
* @param buildNumber the number of the build to promote
* @param promotionRequest the promotion request details
* @param project the project name
* @return the promotion response with messages
* @throws IOException if the promotion fails
*/
BuildPromotionResponse promoteBuild(String buildName, String buildNumber, BuildPromotionRequest promotionRequest, String project) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.jfrog.artifactory.client.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.Map;

/**
* Request for promoting a build in Artifactory
*
* @author rnc
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public interface BuildPromotionRequest {
/**
* The new status of the build
* @return the status
*/
String getStatus();

/**
* An optional comment describing the reason for the promotion
* @return the comment
*/
String getComment();

/**
* The user that invoked promotion from the CI server
* @return the CI user
*/
@JsonProperty("ciUser")
String getCiUser();

/**
* The time when the promotion command was received by Artifactory (ISO8601 format)
* @return the timestamp
*/
String getTimestamp();

/**
* When set to true, performs a dry run of the promotion without executing any operation
* @return true for dry run
*/
@JsonProperty("dryRun")
Boolean getDryRun();

/**
* The repository from which the build contents will be copied or moved
* @return the source repository
*/
@JsonProperty("sourceRepo")
String getSourceRepo();

/**
* The target repository to which the build contents will be copied or moved
* @return the target repository
*/
@JsonProperty("targetRepo")
String getTargetRepo();

/**
* Determines how to perform the build promotion. true = copy, false = move
* @return true to copy, false to move
*/
Boolean getCopy();

/**
* Determines whether to move/copy the build's artifacts
* @return true to include artifacts
*/
Boolean getArtifacts();

/**
* Determines whether to move/copy the build's dependencies
* @return true to include dependencies
*/
Boolean getDependencies();

/**
* An array of dependency scopes
* @return the scopes
*/
List<String> getScopes();

/**
* A list of properties to attach to the build's artifacts
* @return the properties
*/
Map<String, Object> getProperties();

/**
* When set to true, fails and aborts the promotion operation upon receiving an error
* @return true to fail fast
*/
@JsonProperty("failFast")
Boolean getFailFast();
}

// Made with Bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jfrog.artifactory.client.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.List;

/**
* Response from promoting a build in Artifactory
*
* @author rnc
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public interface BuildPromotionResponse {
/**
* Get the list of messages from the promotion operation
* @return the messages
*/
List<PromotionMessage> getMessages();
}

// Made with Bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jfrog.artifactory.client.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* A message returned from a build promotion operation
*
* @author rnc
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public interface PromotionMessage {
/**
* The level of the message (error, warning, info)
* @return the message level
*/
String getLevel();

/**
* The message text
* @return the message
*/
String getMessage();
}

// Made with Bob
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ subprojects {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.21.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.21'
api 'org.jfrog.filespecs:file-specs-java:1.1.2'
api 'org.jfrog.buildinfo:build-info-api:2.+'
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package org.jfrog.artifactory.client.impl;

import org.apache.http.entity.ContentType;
import org.jfrog.artifactory.client.Artifactory;
import org.jfrog.artifactory.client.Builds;
import org.jfrog.artifactory.client.impl.util.Util;
import org.jfrog.artifactory.client.model.AllBuilds;
import org.jfrog.artifactory.client.model.BuildPromotionRequest;
import org.jfrog.artifactory.client.model.BuildPromotionResponse;
import org.jfrog.artifactory.client.model.BuildRuns;
import org.jfrog.artifactory.client.model.impl.AllBuildsImpl;
import org.jfrog.artifactory.client.model.impl.BuildPromotionResponseImpl;
import org.jfrog.artifactory.client.model.impl.BuildRunsImpl;
import org.jfrog.build.api.Build;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* @author yahavi
Expand All @@ -31,6 +39,42 @@ public BuildRuns getBuildRuns(String buildName) throws IOException {
return artifactory.get(getBuilderApi() + buildName, BuildRunsImpl.class, BuildRuns.class);
}

@Override
public void uploadBuild(Build build) throws IOException {
uploadBuild(build, null);
}

@Override
public void uploadBuild(Build build, String project) throws IOException {
String apiPath = getBuilderApi();
if (project != null && !project.isEmpty()) {
apiPath += "?project=" + project;
}

Map<String, String> headers = new HashMap<>();
artifactory.put(apiPath, ContentType.APPLICATION_JSON,
Util.getStringFromObject(build), headers, null, -1,
String.class, null);
}

@Override
public BuildPromotionResponse promoteBuild(String buildName, String buildNumber, BuildPromotionRequest promotionRequest) throws IOException {
return promoteBuild(buildName, buildNumber, promotionRequest, null);
}

@Override
public BuildPromotionResponse promoteBuild(String buildName, String buildNumber, BuildPromotionRequest promotionRequest, String project) throws IOException {
String apiPath = getBuilderApi() + "promote/" + buildName + "/" + buildNumber;
if (project != null && !project.isEmpty()) {
apiPath += "?project=" + project;
}

Map<String, String> headers = new HashMap<>();
return artifactory.post(apiPath, ContentType.APPLICATION_JSON,
Util.getStringFromObject(promotionRequest), headers,
BuildPromotionResponseImpl.class, BuildPromotionResponse.class);
}

public String getBuilderApi() {
return baseApiPath + "/build/";
}
Expand Down
Loading
Loading