The following section provides a sample code for a Before Build Info Save worker.
Note
Authorized JFrog Advanced Security (JAS) users can block publishing of build info. Users without JAS can still use this Worker, but without the Stop Action feature: when trying to use it, the publication will not be blocked.
export default async (
context: PlatformContext,
data: BeforeBuildInfoSaveRequest
): Promise<BeforeBuildInfoSaveResponse> => {
let status: ActionStatus = ActionStatus.UNSPECIFIED;
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) {
status = ActionStatus.PROCEED;
console.log("Artifactory ping success");
} else {
status = ActionStatus.WARN;
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
status = ActionStatus.STOP;
console.error(
`Request failed with status code ${
error.status || "<none>"
} caused by : ${error.message}`
);
}
return {
status,
message: "proceed",
};
};
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with save details sent by Artifactory.
{
"build": { // Object containing information about the build
"name": "buildName", // Name of the build
"number": "buildNumber", // Unique number identifying the build
"started": "1980-01-01T00:00:00.000+0000", // Timestamp indicating when the build started (ISO 8601 format)
"buildAgent": "GENERIC/1.00.0", // Identifier for the build agent used
"agent": "jfrog-cli-go/1.00.0", // Specific CLI agent used for the build
"durationMillis": 1000, // Duration of the build in milliseconds
"principal": "bob", // User who initiated the build
"artifactoryPrincipal": "artifactoryPrincipal", // Principal or user in Artifactory associated with the build
"url": "url", // URL to access the build details or information
"parentName": "parentName", // Name of the parent build (if applicable)
"parentNumber": "parentNumber", // Number of the parent build (if applicable)
"buildRepo": "buildRepo", // Repository where the build artifacts are stored
"modules": [ // Array of modules associated with the build
{
"id": "module1", // Unique identifier for the module
"artifacts": [ // Array of artifacts produced by the module
{
"name": "name", // Name of the artifact
"type": "type", // Type of the artifact (e.g., jar, war, etc.)
"sha1": "sha1", // SHA-1 checksum of the artifact
"sha256": "sha256", // SHA-256 checksum of the artifact
"md5": "md5", // MD5 checksum of the artifact
"remotePath": "remotePath", // Path to the remote location of the artifact
"properties": "properties" // Additional properties associated with the artifact
}
],
"dependencies": [ // Array of dependencies for the module
{
"id": "id", // Unique identifier for the dependency
"scopes": "scopes", // Scopes in which the dependency is used (e.g., compile, runtime)
"requestedBy": "requestedBy" // User or process that requested the dependency
}
]
}
],
"releaseStatus": "releaseStatus", // Release status of the build (e.g., released, unreleased)
"promotionStatuses": [ // Array of promotion statuses for the build
{
"status": "status", // Status of the promotion (e.g., promoted, failed)
"comment": "comment", // Comment or note about the promotion status
"repository": "repository", // Repository involved in the promotion
"timestamp": "timestamp", // Timestamp when the promotion status was recorded
"user": "user", // User who performed the promotion
"ciUser": "ciUser" // CI user associated with the promotion (if applicable)
}
]
}
}
Response
{
"message": "proceed", // Message to print to the log, in case of an error, it will be printed as a warning
"status": "proceed" // The instruction of how to proceed
}
message and status : These are mandatory fields.
Possible Statuses
ActionStatus.PROCEED- The worker allows Artifactory to proceed with build info save events.ActionStatus.STOP- The worker does not allow Artifactory to save build info save events.ActionStatus.WARN- The worker provides a warning before Artifactory can proceed with the build info save events.