Chilkat Online Tools

StopBuild TCL Example

AWS CodeBuild

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 "codebuild"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://codebuild.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "codebuild.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 "id" "string"

# The JSON request body created by the above code:

# {
#   "id": "string"
# }

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "CodeBuild_20161006.StopBuild"

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 Arn [CkJsonObject_stringOf $jResp "build.arn"]
set ArtifactIdentifier [CkJsonObject_stringOf $jResp "build.artifacts.artifactIdentifier"]
set BucketOwnerAccess [CkJsonObject_stringOf $jResp "build.artifacts.bucketOwnerAccess"]
set EncryptionDisabled [CkJsonObject_IntOf $jResp "build.artifacts.encryptionDisabled"]
set Location [CkJsonObject_stringOf $jResp "build.artifacts.location"]
set Md5sum [CkJsonObject_stringOf $jResp "build.artifacts.md5sum"]
set OverrideArtifactName [CkJsonObject_IntOf $jResp "build.artifacts.overrideArtifactName"]
set Sha256sum [CkJsonObject_stringOf $jResp "build.artifacts.sha256sum"]
set BuildBatchArn [CkJsonObject_stringOf $jResp "build.buildBatchArn"]
set BuildComplete [CkJsonObject_IntOf $jResp "build.buildComplete"]
set BuildNumber [CkJsonObject_IntOf $jResp "build.buildNumber"]
set BuildStatus [CkJsonObject_stringOf $jResp "build.buildStatus"]
set CacheLocation [CkJsonObject_stringOf $jResp "build.cache.location"]
set v_Type [CkJsonObject_stringOf $jResp "build.cache.type"]
set CurrentPhase [CkJsonObject_stringOf $jResp "build.currentPhase"]
set SessionEnabled [CkJsonObject_IntOf $jResp "build.debugSession.sessionEnabled"]
set SessionTarget [CkJsonObject_stringOf $jResp "build.debugSession.sessionTarget"]
set EncryptionKey [CkJsonObject_stringOf $jResp "build.encryptionKey"]
set EndTime [CkJsonObject_IntOf $jResp "build.endTime"]
set Certificate [CkJsonObject_stringOf $jResp "build.environment.certificate"]
set ComputeType [CkJsonObject_stringOf $jResp "build.environment.computeType"]
set Image [CkJsonObject_stringOf $jResp "build.environment.image"]
set ImagePullCredentialsType [CkJsonObject_stringOf $jResp "build.environment.imagePullCredentialsType"]
set PrivilegedMode [CkJsonObject_IntOf $jResp "build.environment.privilegedMode"]
set Credential [CkJsonObject_stringOf $jResp "build.environment.registryCredential.credential"]
set CredentialProvider [CkJsonObject_stringOf $jResp "build.environment.registryCredential.credentialProvider"]
set EnvironmentType [CkJsonObject_stringOf $jResp "build.environment.type"]
set Id [CkJsonObject_stringOf $jResp "build.id"]
set Initiator [CkJsonObject_stringOf $jResp "build.initiator"]
set GroupName [CkJsonObject_stringOf $jResp "build.logs.cloudWatchLogs.groupName"]
set Status [CkJsonObject_stringOf $jResp "build.logs.cloudWatchLogs.status"]
set StreamName [CkJsonObject_stringOf $jResp "build.logs.cloudWatchLogs.streamName"]
set CloudWatchLogsArn [CkJsonObject_stringOf $jResp "build.logs.cloudWatchLogsArn"]
set DeepLink [CkJsonObject_stringOf $jResp "build.logs.deepLink"]
set LogsGroupName [CkJsonObject_stringOf $jResp "build.logs.groupName"]
set S3DeepLink [CkJsonObject_stringOf $jResp "build.logs.s3DeepLink"]
set S3LogsBucketOwnerAccess [CkJsonObject_stringOf $jResp "build.logs.s3Logs.bucketOwnerAccess"]
set S3LogsEncryptionDisabled [CkJsonObject_IntOf $jResp "build.logs.s3Logs.encryptionDisabled"]
set S3LogsLocation [CkJsonObject_stringOf $jResp "build.logs.s3Logs.location"]
set S3LogsStatus [CkJsonObject_stringOf $jResp "build.logs.s3Logs.status"]
set S3LogsArn [CkJsonObject_stringOf $jResp "build.logs.s3LogsArn"]
set LogsStreamName [CkJsonObject_stringOf $jResp "build.logs.streamName"]
set NetworkInterfaceId [CkJsonObject_stringOf $jResp "build.networkInterface.networkInterfaceId"]
set SubnetId [CkJsonObject_stringOf $jResp "build.networkInterface.subnetId"]
set ProjectName [CkJsonObject_stringOf $jResp "build.projectName"]
set QueuedTimeoutInMinutes [CkJsonObject_IntOf $jResp "build.queuedTimeoutInMinutes"]
set ResolvedSourceVersion [CkJsonObject_stringOf $jResp "build.resolvedSourceVersion"]
set ServiceRole [CkJsonObject_stringOf $jResp "build.serviceRole"]
set Resource [CkJsonObject_stringOf $jResp "build.source.auth.resource"]
set AuthType [CkJsonObject_stringOf $jResp "build.source.auth.type"]
set Buildspec [CkJsonObject_stringOf $jResp "build.source.buildspec"]
set Context [CkJsonObject_stringOf $jResp "build.source.buildStatusConfig.context"]
set TargetUrl [CkJsonObject_stringOf $jResp "build.source.buildStatusConfig.targetUrl"]
set GitCloneDepth [CkJsonObject_IntOf $jResp "build.source.gitCloneDepth"]
set FetchSubmodules [CkJsonObject_IntOf $jResp "build.source.gitSubmodulesConfig.fetchSubmodules"]
set InsecureSsl [CkJsonObject_IntOf $jResp "build.source.insecureSsl"]
set SourceLocation [CkJsonObject_stringOf $jResp "build.source.location"]
set ReportBuildStatus [CkJsonObject_IntOf $jResp "build.source.reportBuildStatus"]
set SourceIdentifier [CkJsonObject_stringOf $jResp "build.source.sourceIdentifier"]
set SourceType [CkJsonObject_stringOf $jResp "build.source.type"]
set SourceVersion [CkJsonObject_stringOf $jResp "build.sourceVersion"]
set StartTime [CkJsonObject_IntOf $jResp "build.startTime"]
set TimeoutInMinutes [CkJsonObject_IntOf $jResp "build.timeoutInMinutes"]
set VpcId [CkJsonObject_stringOf $jResp "build.vpcConfig.vpcId"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.cache.modes"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "build.cache.modes[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.environment.environmentVariables"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set name [CkJsonObject_stringOf $jResp "build.environment.environmentVariables[i].name"]
    set v_type [CkJsonObject_stringOf $jResp "build.environment.environmentVariables[i].type"]
    set value [CkJsonObject_stringOf $jResp "build.environment.environmentVariables[i].value"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.exportedEnvironmentVariables"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set name [CkJsonObject_stringOf $jResp "build.exportedEnvironmentVariables[i].name"]
    set value [CkJsonObject_stringOf $jResp "build.exportedEnvironmentVariables[i].value"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.fileSystemLocations"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set identifier [CkJsonObject_stringOf $jResp "build.fileSystemLocations[i].identifier"]
    set location [CkJsonObject_stringOf $jResp "build.fileSystemLocations[i].location"]
    set mountOptions [CkJsonObject_stringOf $jResp "build.fileSystemLocations[i].mountOptions"]
    set mountPoint [CkJsonObject_stringOf $jResp "build.fileSystemLocations[i].mountPoint"]
    set v_type [CkJsonObject_stringOf $jResp "build.fileSystemLocations[i].type"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.phases"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set durationInSeconds [CkJsonObject_IntOf $jResp "build.phases[i].durationInSeconds"]
    set endTime [CkJsonObject_IntOf $jResp "build.phases[i].endTime"]
    set phaseStatus [CkJsonObject_stringOf $jResp "build.phases[i].phaseStatus"]
    set phaseType [CkJsonObject_stringOf $jResp "build.phases[i].phaseType"]
    set startTime [CkJsonObject_IntOf $jResp "build.phases[i].startTime"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "build.phases[i].contexts"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set message [CkJsonObject_stringOf $jResp "build.phases[i].contexts[j].message"]
        set statusCode [CkJsonObject_stringOf $jResp "build.phases[i].contexts[j].statusCode"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.reportArns"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "build.reportArns[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.secondaryArtifacts"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set artifactIdentifier [CkJsonObject_stringOf $jResp "build.secondaryArtifacts[i].artifactIdentifier"]
    set bucketOwnerAccess [CkJsonObject_stringOf $jResp "build.secondaryArtifacts[i].bucketOwnerAccess"]
    set encryptionDisabled [CkJsonObject_IntOf $jResp "build.secondaryArtifacts[i].encryptionDisabled"]
    set location [CkJsonObject_stringOf $jResp "build.secondaryArtifacts[i].location"]
    set md5sum [CkJsonObject_stringOf $jResp "build.secondaryArtifacts[i].md5sum"]
    set overrideArtifactName [CkJsonObject_IntOf $jResp "build.secondaryArtifacts[i].overrideArtifactName"]
    set sha256sum [CkJsonObject_stringOf $jResp "build.secondaryArtifacts[i].sha256sum"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.secondarySources"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set authResource [CkJsonObject_stringOf $jResp "build.secondarySources[i].auth.resource"]
    set authType [CkJsonObject_stringOf $jResp "build.secondarySources[i].auth.type"]
    set buildspec [CkJsonObject_stringOf $jResp "build.secondarySources[i].buildspec"]
    set buildStatusConfigContext [CkJsonObject_stringOf $jResp "build.secondarySources[i].buildStatusConfig.context"]
    set buildStatusConfigTargetUrl [CkJsonObject_stringOf $jResp "build.secondarySources[i].buildStatusConfig.targetUrl"]
    set gitCloneDepth [CkJsonObject_IntOf $jResp "build.secondarySources[i].gitCloneDepth"]
    set gitSubmodulesConfigFetchSubmodules [CkJsonObject_IntOf $jResp "build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules"]
    set insecureSsl [CkJsonObject_IntOf $jResp "build.secondarySources[i].insecureSsl"]
    set location [CkJsonObject_stringOf $jResp "build.secondarySources[i].location"]
    set reportBuildStatus [CkJsonObject_IntOf $jResp "build.secondarySources[i].reportBuildStatus"]
    set sourceIdentifier [CkJsonObject_stringOf $jResp "build.secondarySources[i].sourceIdentifier"]
    set v_type [CkJsonObject_stringOf $jResp "build.secondarySources[i].type"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.secondarySourceVersions"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set sourceIdentifier [CkJsonObject_stringOf $jResp "build.secondarySourceVersions[i].sourceIdentifier"]
    set sourceVersion [CkJsonObject_stringOf $jResp "build.secondarySourceVersions[i].sourceVersion"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.vpcConfig.securityGroupIds"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "build.vpcConfig.securityGroupIds[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "build.vpcConfig.subnets"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "build.vpcConfig.subnets[i]"]
    set i [expr $i + 1]
}

# A sample JSON response body parsed by the above code:

# {
#   "build": {
#     "arn": "string",
#     "artifacts": {
#       "artifactIdentifier": "string",
#       "bucketOwnerAccess": "string",
#       "encryptionDisabled": boolean,
#       "location": "string",
#       "md5sum": "string",
#       "overrideArtifactName": boolean,
#       "sha256sum": "string"
#     },
#     "buildBatchArn": "string",
#     "buildComplete": boolean,
#     "buildNumber": number,
#     "buildStatus": "string",
#     "cache": {
#       "location": "string",
#       "modes": [
#         "string"
#       ],
#       "type": "string"
#     },
#     "currentPhase": "string",
#     "debugSession": {
#       "sessionEnabled": boolean,
#       "sessionTarget": "string"
#     },
#     "encryptionKey": "string",
#     "endTime": number,
#     "environment": {
#       "certificate": "string",
#       "computeType": "string",
#       "environmentVariables": [
#         {
#           "name": "string",
#           "type": "string",
#           "value": "string"
#         }
#       ],
#       "image": "string",
#       "imagePullCredentialsType": "string",
#       "privilegedMode": boolean,
#       "registryCredential": {
#         "credential": "string",
#         "credentialProvider": "string"
#       },
#       "type": "string"
#     },
#     "exportedEnvironmentVariables": [
#       {
#         "name": "string",
#         "value": "string"
#       }
#     ],
#     "fileSystemLocations": [
#       {
#         "identifier": "string",
#         "location": "string",
#         "mountOptions": "string",
#         "mountPoint": "string",
#         "type": "string"
#       }
#     ],
#     "id": "string",
#     "initiator": "string",
#     "logs": {
#       "cloudWatchLogs": {
#         "groupName": "string",
#         "status": "string",
#         "streamName": "string"
#       },
#       "cloudWatchLogsArn": "string",
#       "deepLink": "string",
#       "groupName": "string",
#       "s3DeepLink": "string",
#       "s3Logs": {
#         "bucketOwnerAccess": "string",
#         "encryptionDisabled": boolean,
#         "location": "string",
#         "status": "string"
#       },
#       "s3LogsArn": "string",
#       "streamName": "string"
#     },
#     "networkInterface": {
#       "networkInterfaceId": "string",
#       "subnetId": "string"
#     },
#     "phases": [
#       {
#         "contexts": [
#           {
#             "message": "string",
#             "statusCode": "string"
#           }
#         ],
#         "durationInSeconds": number,
#         "endTime": number,
#         "phaseStatus": "string",
#         "phaseType": "string",
#         "startTime": number
#       }
#     ],
#     "projectName": "string",
#     "queuedTimeoutInMinutes": number,
#     "reportArns": [
#       "string"
#     ],
#     "resolvedSourceVersion": "string",
#     "secondaryArtifacts": [
#       {
#         "artifactIdentifier": "string",
#         "bucketOwnerAccess": "string",
#         "encryptionDisabled": boolean,
#         "location": "string",
#         "md5sum": "string",
#         "overrideArtifactName": boolean,
#         "sha256sum": "string"
#       }
#     ],
#     "secondarySources": [
#       {
#         "auth": {
#           "resource": "string",
#           "type": "string"
#         },
#         "buildspec": "string",
#         "buildStatusConfig": {
#           "context": "string",
#           "targetUrl": "string"
#         },
#         "gitCloneDepth": number,
#         "gitSubmodulesConfig": {
#           "fetchSubmodules": boolean
#         },
#         "insecureSsl": boolean,
#         "location": "string",
#         "reportBuildStatus": boolean,
#         "sourceIdentifier": "string",
#         "type": "string"
#       }
#     ],
#     "secondarySourceVersions": [
#       {
#         "sourceIdentifier": "string",
#         "sourceVersion": "string"
#       }
#     ],
#     "serviceRole": "string",
#     "source": {
#       "auth": {
#         "resource": "string",
#         "type": "string"
#       },
#       "buildspec": "string",
#       "buildStatusConfig": {
#         "context": "string",
#         "targetUrl": "string"
#       },
#       "gitCloneDepth": number,
#       "gitSubmodulesConfig": {
#         "fetchSubmodules": boolean
#       },
#       "insecureSsl": boolean,
#       "location": "string",
#       "reportBuildStatus": boolean,
#       "sourceIdentifier": "string",
#       "type": "string"
#     },
#     "sourceVersion": "string",
#     "startTime": number,
#     "timeoutInMinutes": number,
#     "vpcConfig": {
#       "securityGroupIds": [
#         "string"
#       ],
#       "subnets": [
#         "string"
#       ],
#       "vpcId": "string"
#     }
#   }
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp