Chilkat Online Tools

BatchGetBuilds 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 "ids[0]" "string"

# The JSON request body created by the above code:

# {
#   "ids": [
#     "string"
#   ]
# }

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

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

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

# {
#   "builds": [
#     {
#       "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"
#       }
#     }
#   ],
#   "buildsNotFound": [
#     "string"
#   ]
# }

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