Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Build Property Setter
=====================================

This worker is triggered by the `AFTER_BUILD_INFO_SAVE` event of Artifactory. Its primary purpose is to remove the "latest=true" property from any artifacts in previous builds and set the same property on the artifacts corresponding to the current build that was saved.

Functionality
-------------
- **Removing property:** Removes "latest=true" from artifacts in past builds.
- **Adding property:** Sets "latest=true" for artifacts in the current build.

Worker Logic
------------
1. **Removing latest from previous build's artifacts**:
- Find the previous build numbers for the same build name.
- Find the unique artifacts from the past builds.
- Use the delete property API to remove the property from these artifacts.
2. **Setting latest for artifacts in current build**:
- Fetch artifacts from the current build.
- Use the set property API to set `latest=true` for each of these artifacts.

Payload
-------
The worker operates on the `AFTER_BUILD_INFO_SAVE` event payload provided by Artifactory. It uses the build name and build number to fetch the artifact details.

Possible Responses
------------------

### Success
- **Structure:**
```json
{
"data": {
"message": "Successfully set property for artifacts",
"executionStatus": 4
},
"executionStatus": "STATUS_SUCCESS"
}
```
- **Explanation:**
- Indicates that only the artifacts present in the build (if any) will now have the property `latest=true` set.

### Failed
- **Structure:**
```json
{
"data": {
"message": "Error occurred",
"executionStatus": 2
},
"executionStatus": "STATUS_FAIL"
}
```
- **Explanation:**
- Indicates there was an error in fetching details or setting the property.

Recommendations
---------------

- **Testing**:
- Validate the worker functionality in a staging environment before deploying to production.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "build-property-setter",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this was already discussed with PM, but this name looks a bit too much generic to me

Suggested change
"name": "build-property-setter",
"name": "build-mark-latest-artifacts",

"description": "Removes 'latest=true' from previous build artifacts and sets it for current build artifacts after build info is saved.",
"filterCriteria": {
"artifactFilterCriteria": {
"repoKeys": [
"example-repo-local"
]
}
},
"secrets": {},
"sourceCodePath": "./worker.ts",
"action": "AFTER_BUILD_INFO_SAVE",
"enabled": false,
"debug": true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the code gallery takes it into account anyway

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it, then

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "build-property-setter",
"description": "Run a script on AFTER_BUILD_INFO_SAVE",
"version": "1.0.0",
"scripts": {
"deploy": "jf worker deploy",
"undeploy": "jf worker rm \"build-property-setter\"",
"test": "jest"
},
"license": "ISC",
"devDependencies": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use exact dependencies?

"jfrog-workers": "^0.4.0",
"@golevelup/ts-jest": "^0.4.0",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"jest-jasmine2": "^29.7.0",
"ts-jest": "^29.1.2"
},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"rootDir": ".",
"testEnvironment": "node",
"clearMocks": true,
"maxConcurrency": 1,
"testRegex": "\\.spec\\.ts$",
"moduleDirectories": [
"node_modules"
],
"collectCoverageFrom": [
"**/*.ts"
],
"coverageDirectory": "../coverage",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"testRunner": "jest-jasmine2",
"verbose": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"target": "es2017",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so old?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is what the CLI generates: https://github.com/jfrog/jfrog-cli-platform-services/blob/main/commands/templates/tsconfig.json_template

We are currently using ES2022 on server side indeed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christophermiJfrog Should we fix the CLI, then?

"skipLibCheck": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"allowJs": true
},
"include": [
"**/*.ts",
"node_modules/@types/**/*.d.ts"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
interface DetailedBuildRun {
name: string;
number: string;
started: string;
buildAgent: string;
agent: string;
durationMillis: number;
principal: string;
artifactoryPrincipal: string;
url: string;
parentName: string;
parentNumber: string;
buildRepo: string;
modules: Module[];
releaseStatus: string;
promotionStatuses: PromotionStatus[];
}

interface Module {
id: string;
artifacts: Artifact[];
dependencies: Dependency[];
}

interface Artifact {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good practice to add all the provided field, instead of just add those that are actually in use by the worker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is generated by the CLI: https://github.com/jfrog/jfrog-cli-platform-services/blob/main/commands/init_cmd.go#L180. This gives autocompletion experience while working on the Worker's code

name: string;
type: string;
sha1: string;
sha256: string;
md5: string;
remotePath: string;
properties: string;
}

interface Dependency {
id: string;
scopes: string;
requestedBy: string;
}

interface PromotionStatus {
status: string;
comment: string;
repository: string;
timestamp: string;
user: string;
ciUser: string;
}

export interface AfterBuildInfoSaveRequest {
/** Various immutable build run details */
build: DetailedBuildRun;
}

export interface ArtifactPathInfo {
repo: string;
path: string;
}
Loading