To create a pipeline, you make a POST request and provide the endpoint ID. Then you use the ID of the pipeline created in a PATCH request to enable it.

The following procedure shows how to create a pipeline with a Jenkins task using the Jenkins endpoint that you created. Then you enable the pipeline to run.

Prerequisites

Procedure

  1. Assign the project ID variable.
    project_id='<your_project_id>'
  2. Assign the endpoint name variable.
    endpoint_name="'<your_endpoint_name>'"
  3. Create the pipeline with a Jenkins task.
    • For job, provide the job on the Jenkins server that your pipeline will run.
    • For parameters, provide the parameters that will be passed to the job.
    curl -X POST \
      $url/codestream/api/pipelines?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token"  \
      -d '{
    	"project": "'$project_id'",
    	"kind": "PIPELINE",
    	"name": "'<your_pipeline_name>'",
    	"concurrency": 10,
    	"stageOrder": ["Stage0"],
    	"stages": {
    		"Stage0": {
    			"taskOrder": ["Task0"],
    			"tags": [],
    			"tasks": {
    				"Task0": {
    					"type": "Jenkins",
    					"ignoreFailure": false,
    					"preCondition": "",
    					"input": {
    						"job": "'<your_job_name>",
    						"jobFolder": "",
    						"parameters": {
    							"'<your_parameters>'": ""
    						}
    					},
    					"endpoints": {
    						"jenkinsServer": "'$endpoint_name'"
    					},
    					"tags": [],
    					"_configured": true
    				}
    			}
    		}
    	}
    }' | jq "."
    A snippet of the response shows the pipeline ID with the pipeline disabled. Assign a variable for the pipeline ID.
    pipeline_id='<your_pipeline_id>'
  4. Enable the pipeline.
    curl -X PATCH \
      $url/codestream/api/pipelines/$pipeline_id?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token"  \
      -d '{"state": "ENABLED"}' | jq "."
    The response shows the pipeline state changed to "state": "ENABLED".

Example: Create and Enable a Pipeline

Using the endpoint named jenkins-example that you created, create a pipeline named jenkinspipeline with a Jenkins task.

Assign variables.

$ url='https://appliance.domain.com'
$ api_version='2019-10-17'
$ project_id='MyProject1'
$ endpoint_name='jenkins-example'

Create the pipeline with a Jenkins task.

$ curl -X POST \
  $url/codestream/api/pipelines?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token"  \
  -d '{
	"project": "'$project_id'",
	"kind": "PIPELINE",
	"name": "jenkinspipeline",
	"concurrency": 10,
	"stageOrder": ["Stage0"],
	"stages": {
		"Stage0": {
			"taskOrder": ["Task0"],
			"tags": [],
			"tasks": {
				"Task0": {
					"type": "Jenkins",
					"ignoreFailure": false,
					"preCondition": "",
					"input": {
						"job": "Build-DemoApp",
						"jobFolder": "",
						"parameters": {
							"vRCSTestExecutionId": ""
						}
					},
					"endpoints": {
						"jenkinsServer": "'$endpoint_name'"
					},
					"tags": [],
					"_configured": true
				}
			}
		}
	}
}' | jq "."

A snippet of the response shows the pipeline ID and shows the state of the pipeline as disabled.

{
	"project": "MyProject1",
	"kind": "PIPELINE",
	"id": "2677aa61-578a-4465-a653-a3c787fed3be",
	"name": "jenkinspipeline",
	"createdBy": "[email protected]",
	"updatedBy": "[email protected]",
	"createdAt": "2022-11-04T11:20:09.905+0000",
	"updatedAt": "2022-11-04T11:23:40.971+0000",
	"_link": "/codestream/api/pipelines/2677aa61-578a-4465-a653-a3c787fed3be",
       ...
	"rollbacks": [],
	"tags": [],
	"state": "DISABLED"
}

Assign a variable for the pipeline ID.

$ pipeline_id="2677aa61-578a-4465-a653-a3c787fed3be"

Enable the pipeline.

$ curl -X PATCH \
  $url/codestream/api/pipelines/$pipeline_id?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token"  \
  -d '{"state": "ENABLED"}' | jq "."

A snippet of the response shows the state of the pipeline is enabled.

{
	"project": "MyProject1",
	"kind": "PIPELINE",
	"id": "2677aa61-578a-4465-a653-a3c787fed3be",
	"name": "jenkinspipeline",
	"createdBy": "[email protected]",
	"updatedBy": "[email protected]",
	"createdAt": "2022-11-04T11:20:09.905+0000",
	"updatedAt": "2022-11-04T11:24:50.693+0000",
	"_link": "/codestream/api/pipelines/2677aa61-578a-4465-a653-a3c787fed3be",
       ...
	"rollbacks": [],
	"tags": [],
	"state": "ENABLED"
}

What to do next

Run your pipeline.