CreatePipeline TCL Example
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rest [new_CkRest]
set authAws [new_CkAuthAws]
CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "AWS_SECRET_KEY"
# Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "codepipeline"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws
# URL: https://codepipeline.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "codepipeline.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
exit
}
# The following code creates the JSON request body.
# The JSON created by this code is shown below.
# Use this online tool to generate code from sample JSON:
# Generate Code to Create JSON
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "pipeline.artifactStore.encryptionKey.id" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStore.encryptionKey.type" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStore.location" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStore.type" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStores.string.encryptionKey.id" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStores.string.encryptionKey.type" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStores.string.location" "string"
CkJsonObject_UpdateString $json "pipeline.artifactStores.string.type" "string"
CkJsonObject_UpdateString $json "pipeline.name" "string"
CkJsonObject_UpdateString $json "pipeline.roleArn" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].actionTypeId.category" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].actionTypeId.owner" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].actionTypeId.provider" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].actionTypeId.version" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].configuration.string" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].inputArtifacts[0].name" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].name" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].namespace" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].outputArtifacts[0].name" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].region" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].actions[0].roleArn" "string"
CkJsonObject_UpdateInt $json "pipeline.stages[0].actions[0].runOrder" 123
CkJsonObject_UpdateString $json "pipeline.stages[0].blockers[0].name" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].blockers[0].type" "string"
CkJsonObject_UpdateString $json "pipeline.stages[0].name" "string"
CkJsonObject_UpdateInt $json "pipeline.version" 123
CkJsonObject_UpdateString $json "tags[0].key" "string"
CkJsonObject_UpdateString $json "tags[0].value" "string"
# The JSON request body created by the above code:
# {
# "pipeline": {
# "artifactStore": {
# "encryptionKey": {
# "id": "string",
# "type": "string"
# },
# "location": "string",
# "type": "string"
# },
# "artifactStores": {
# "string": {
# "encryptionKey": {
# "id": "string",
# "type": "string"
# },
# "location": "string",
# "type": "string"
# }
# },
# "name": "string",
# "roleArn": "string",
# "stages": [
# {
# "actions": [
# {
# "actionTypeId": {
# "category": "string",
# "owner": "string",
# "provider": "string",
# "version": "string"
# },
# "configuration": {
# "string": "string"
# },
# "inputArtifacts": [
# {
# "name": "string"
# }
# ],
# "name": "string",
# "namespace": "string",
# "outputArtifacts": [
# {
# "name": "string"
# }
# ],
# "region": "string",
# "roleArn": "string",
# "runOrder": number
# }
# ],
# "blockers": [
# {
# "name": "string",
# "type": "string"
# }
# ],
# "name": "string"
# }
# ],
# "version": number
# },
# "tags": [
# {
# "key": "string",
# "value": "string"
# }
# ]
# }
CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "CodePipeline_20150709.CreatePipeline"
set sbRequestBody [new_CkStringBuilder]
CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]
set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
puts "Response Header:"
puts [CkRest_responseHeader $rest]
puts "Response Body:"
puts [CkStringBuilder_getAsString $sbResponseBody]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
# The following code parses the JSON response.
# A sample JSON response is shown below the sample code.
# Use this online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON
set Id [CkJsonObject_stringOf $jResp "pipeline.artifactStore.encryptionKey.id"]
set v_Type [CkJsonObject_stringOf $jResp "pipeline.artifactStore.encryptionKey.type"]
set Location [CkJsonObject_stringOf $jResp "pipeline.artifactStore.location"]
set ArtifactStoreType [CkJsonObject_stringOf $jResp "pipeline.artifactStore.type"]
set EncryptionKeyId [CkJsonObject_stringOf $jResp "pipeline.artifactStores.string.encryptionKey.id"]
set EncryptionKeyType [CkJsonObject_stringOf $jResp "pipeline.artifactStores.string.encryptionKey.type"]
set StringLocation [CkJsonObject_stringOf $jResp "pipeline.artifactStores.string.location"]
set StringType [CkJsonObject_stringOf $jResp "pipeline.artifactStores.string.type"]
set Name [CkJsonObject_stringOf $jResp "pipeline.name"]
set RoleArn [CkJsonObject_stringOf $jResp "pipeline.roleArn"]
set Version [CkJsonObject_IntOf $jResp "pipeline.version"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "pipeline.stages"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set name [CkJsonObject_stringOf $jResp "pipeline.stages[i].name"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "pipeline.stages[i].actions"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set Category [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].actionTypeId.category"]
set Owner [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].actionTypeId.owner"]
set Provider [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].actionTypeId.provider"]
set actionTypeIdVersion [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].actionTypeId.version"]
set v_String [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].configuration.string"]
set name [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].name"]
set namespace [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].namespace"]
set region [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].region"]
set roleArn [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].roleArn"]
set runOrder [CkJsonObject_IntOf $jResp "pipeline.stages[i].actions[j].runOrder"]
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "pipeline.stages[i].actions[j].inputArtifacts"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set name [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].inputArtifacts[k].name"]
set k [expr $k + 1]
}
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "pipeline.stages[i].actions[j].outputArtifacts"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set name [CkJsonObject_stringOf $jResp "pipeline.stages[i].actions[j].outputArtifacts[k].name"]
set k [expr $k + 1]
}
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "pipeline.stages[i].blockers"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set name [CkJsonObject_stringOf $jResp "pipeline.stages[i].blockers[j].name"]
set v_type [CkJsonObject_stringOf $jResp "pipeline.stages[i].blockers[j].type"]
set j [expr $j + 1]
}
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "tags"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set key [CkJsonObject_stringOf $jResp "tags[i].key"]
set value [CkJsonObject_stringOf $jResp "tags[i].value"]
set i [expr $i + 1]
}
# A sample JSON response body parsed by the above code:
# {
# "pipeline": {
# "artifactStore": {
# "encryptionKey": {
# "id": "string",
# "type": "string"
# },
# "location": "string",
# "type": "string"
# },
# "artifactStores": {
# "string": {
# "encryptionKey": {
# "id": "string",
# "type": "string"
# },
# "location": "string",
# "type": "string"
# }
# },
# "name": "string",
# "roleArn": "string",
# "stages": [
# {
# "actions": [
# {
# "actionTypeId": {
# "category": "string",
# "owner": "string",
# "provider": "string",
# "version": "string"
# },
# "configuration": {
# "string": "string"
# },
# "inputArtifacts": [
# {
# "name": "string"
# }
# ],
# "name": "string",
# "namespace": "string",
# "outputArtifacts": [
# {
# "name": "string"
# }
# ],
# "region": "string",
# "roleArn": "string",
# "runOrder": number
# }
# ],
# "blockers": [
# {
# "name": "string",
# "type": "string"
# }
# ],
# "name": "string"
# }
# ],
# "version": number
# },
# "tags": [
# {
# "key": "string",
# "value": "string"
# }
# ]
# }
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp