Using the latest JFrog products?
JFrog Platform User Guide
JFrog Mission Control 3.x Documentation
To get the latest version, go to the JFrog Unified Platform
Examples
The following examples show how to run scripts through the REST API with user input.
Example 1 - Modifying a Repository
The following script modifies thedescriptionfield of a local repository called "my-repository" in an Artifactory service called "Denver" according to user input. Assume the script is calledmodify-description
artifactory('Denver'){ localRepository("my-repository") { description userInput ( type : "STRING", value : "This is a generic description", description : "Please provide a description" ) } }
Call Get Script User Input
To get the user input required for the script, you need to make the following REST API call:$ curl -XGET 'http://localhost:8080/api/v3/scripts/modify-description/user_inputs' -uadmin:password
This will return the following JSON object:
{" ArtifactoryDsl # 0 # LocalRepositoryDsl # 0 # description#0": { "name": "description", "description": "Please provide a description", "value": "This is a generic description", "type": "STRING", "multivalued": false } }
Execute the script with the modified user input value
$ curl -XPUT 'http://localhost:8080/api/v3/execute_script/modify-description' -uadmin:password -H 'Content-Type: application/json; charset=UTF-8' -T scriptinput.json
where we pass in the script input JSON object as the following file:
scriptinput.json{" ArtifactoryDsl # 0 # LocalRepositoryDsl # 0 # description#0": "*** This is my new description ***" }
This produces the following output:
[ { "instance": { "name": "Denver", "url": "http://artifactory-adi.jfrogdev.co/artifactory", "type": "ARTIFACTORY" }, "status": "OK", "execution_duration": 514, "operation": "UPDATE_REPOSITORY" } ]
Example 2 - Selecting the Artifactory Service to Modify
在这个例子中,我们将修改的描述a local repository as in the previous example, however we will also receive the Artifactory service on which to make the change as user input. Assume the script is calledmodify-description-select-service
name = userInput ( type : "STRING", value : "Insert Artifactory Name", description : "Please provide Service name" ) artifactory(name){ localRepository("my-repository") { description userInput ( type : "STRING", value : "This is a generic description", description : "Please provide a description" ) } }
Call Get Script User Input
$ curl -XGET 'http://localhost:8080/api/v3/scripts/modify-description-select-service/user_inputs' -uadmin:password
This will return the following JSON object:
{ "McDsl#0#name#0": { "name": "name", "description": "Please provide Service name", "value": "Insert Artifactory Name", "type": "STRING", "multivalued": false }, "ArtifactoryDsl#0#LocalRepositoryDsl#0#description#0": { "name": "description", "description": "Please provide a description", "value": "This is a generic description", "type": "STRING", "multivalued": false } }
Execute the script with the modified user input value
$ curl -XPUT 'http://localhost:8080/api/v3/execute_script/modify-description-select-service' -uadmin:password -H 'Content-Type: application/json; charset=UTF-8' -T scriptinput.json
where we pass in the script input JSON object as the following file:
scriptinput.json{ "McDsl#0#name#0": "Denver", "ArtifactoryDsl#0#LocalRepositoryDsl#0#description#0": "description for local repository" }