Overview

Mission Control provides you the flexibility of using placeholders in configuration scripts so that the user can enter user input when the scripts are applied.

The REST API supports this capability through the Get Script User Input REST API call. 

Running a Script with User Input

Running a script with user input through the REST API is done through the following main steps:

  1. Run the Get Script User Input REST API endpoint on the script.
    This will return a JSON object specifying the user input required
  2. Modify the name property of the required user input fields in the JSON object
  3. Run the Execute Script REST API endpoint passing in the modified user input JSON object as input 


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 the description field of a local repository called "my-repository" in an Artifactory service called "Denver" according to user input. Assume the script is called modify-description

artifactory('Denver'){
	localRepository("my-repository") {
  		description userInput (
    				type : "STRING",
    				value : "This is a generic description",
    				description : "Please provide a description"
  		)
	}
}
  1. 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
        }
    }

     

     

  2. 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:

    {
        "ArtifactoryDsl#0#LocalRepositoryDsl#0#description#0": "*** This is my new description ***"
    }
  3. 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

In this example, we will modify the description of 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 called modify-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"
        )
    }
}

 

  1. 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
        }
    }
  2. 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:

    {
        "McDsl#0#name#0": "Denver",
        "ArtifactoryDsl#0#LocalRepositoryDsl#0#description#0": "description for local repository"
    }