The following section provides a sample code for a Before Upload worker.
export default async (
context: PlatformContext,
data: AfterBuildInfoSaveRequest
): Promise<AfterBuildInfoSaveResponse> => {
try {
// The HTTP client facilitates calls to the JFrog Platform REST APIs
//To call an external endpoint, use 'await context.clients.axios.get("https://foo.com")'
const res = await context.clients.platformHttp.get(
"/artifactory/api/v1/system/readiness"
);
// You should reach this part if the HTTP request status is successful (HTTP Status 399 or lower)
if (res.status === 200) {
console.log("Artifactory ping success");
} else {
console.warn(
`Request was successful and returned status code : ${res.status}`
);
}
} catch (error) {
// The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher
console.error(
`Request failed with status code ${
error.status || "<none>"
} caused by : ${error.message}`
);
}
return {
message: "proceed",
executionStatus: Status.STATUS_SUCCESS,
};
};
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with upload details sent by Artifactory.
{
"build": {
"name": "buildName", // The name of the build, used for identification.
"number": "buildNumber", // A unique identifier for this build instance.
"started": "startDate", // The date and time when the build process started.
"buildAgent": "buildAgent", // The name of the build agent that executed the build.
"agent": "agent", // Another identifier for the build agent.
"durationMillis": 1000, // Total time taken for the build in milliseconds.
"principal": "principal", // The user responsible for initiating the build.
"artifactoryPrincipal": "artifactoryPrincipal", // User associated with artifact storage.
"url": "url", // A link to the build details or logs.
"parentName": "parentName", // Name of the parent build, if applicable.
"parentNumber": "parentNumber", // Unique identifier for the parent build.
"buildRepo": "buildRepo", // Repository where the source code for the build is stored.
"modules": [ // List of modules included in this build.
{
"id": "module1", // Unique identifier for the module.
"artifacts": [ // Collection of artifacts produced by the module.
{
"name": "name", // Name of the artifact (output file/package).
"type": "type", // Type/category of the artifact (e.g., jar, zip).
"remotePath": "remotePath", // Path where the artifact is stored remotely.
"properties": "prop2" // Other metadata related to the artifact.
}
],
"dependencies": [ // List of dependencies required by the module.
{
"id": "id", // Unique identifier for the dependency.
"scopes": "scopes", // Scopes in which the dependency is used (e.g., compile, runtime).
"requestedBy": "requestedBy" // Identifies who requested the dependency.
}
]
}
],
"releaseStatus": "releaseStatus", // Current status of the build in terms of release readiness.
"promotionStatuses": [ // History of promotional statuses for this build.
{
"status": "status", // Current status of the promotion process (e.g., promoted, rejected).
"comment": "comment", // Remarks associated with the promotional status.
"repository": "repository", // Repository related to the promotional status.
"timestamp": "timestamp", // Date and time when the promotional status was recorded.
"user": "user", // User who made the promotional change.
"ciUser": "ciUser" // User under which the CI process ran during promotion.
}
]
}
}
Response
{
"message": "proceed" // Message to print to the log, in case of an error, it will be printed as a warning
}
message : This is a mandatory field.