Chilkat Online Tools

StartBuild Python Example

AWS CodeBuild

import sys
import chilkat

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

rest = chilkat.CkRest()

authAws = chilkat.CkAuthAws()
authAws.put_AccessKey("AWS_ACCESS_KEY")
authAws.put_SecretKey("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.)
authAws.put_Region("us-west-2")
authAws.put_ServiceName("codebuild")
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)

# URL: https://codebuild.us-west-2.amazonaws.com/
# Use the same region as specified above.
success = rest.Connect("codebuild.us-west-2.amazonaws.com",443,True,True)
if (success != True):
    print("ConnectFailReason: " + str(rest.get_ConnectFailReason()))
    print(rest.lastErrorText())
    sys.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

json = chilkat.CkJsonObject()
json.UpdateString("artifactsOverride.artifactIdentifier","string")
json.UpdateString("artifactsOverride.bucketOwnerAccess","string")
json.UpdateInt("artifactsOverride.encryptionDisabled",123)
json.UpdateString("artifactsOverride.location","string")
json.UpdateString("artifactsOverride.name","string")
json.UpdateString("artifactsOverride.namespaceType","string")
json.UpdateInt("artifactsOverride.overrideArtifactName",123)
json.UpdateString("artifactsOverride.packaging","string")
json.UpdateString("artifactsOverride.path","string")
json.UpdateString("artifactsOverride.type","string")
json.UpdateString("buildspecOverride","string")
json.UpdateString("buildStatusConfigOverride.context","string")
json.UpdateString("buildStatusConfigOverride.targetUrl","string")
json.UpdateString("cacheOverride.location","string")
json.UpdateString("cacheOverride.modes[0]","string")
json.UpdateString("cacheOverride.type","string")
json.UpdateString("certificateOverride","string")
json.UpdateString("computeTypeOverride","string")
json.UpdateInt("debugSessionEnabled",123)
json.UpdateString("encryptionKeyOverride","string")
json.UpdateString("environmentTypeOverride","string")
json.UpdateString("environmentVariablesOverride[0].name","string")
json.UpdateString("environmentVariablesOverride[0].type","string")
json.UpdateString("environmentVariablesOverride[0].value","string")
json.UpdateInt("gitCloneDepthOverride",123)
json.UpdateInt("gitSubmodulesConfigOverride.fetchSubmodules",123)
json.UpdateString("idempotencyToken","string")
json.UpdateString("imageOverride","string")
json.UpdateString("imagePullCredentialsTypeOverride","string")
json.UpdateInt("insecureSslOverride",123)
json.UpdateString("logsConfigOverride.cloudWatchLogs.groupName","string")
json.UpdateString("logsConfigOverride.cloudWatchLogs.status","string")
json.UpdateString("logsConfigOverride.cloudWatchLogs.streamName","string")
json.UpdateString("logsConfigOverride.s3Logs.bucketOwnerAccess","string")
json.UpdateInt("logsConfigOverride.s3Logs.encryptionDisabled",123)
json.UpdateString("logsConfigOverride.s3Logs.location","string")
json.UpdateString("logsConfigOverride.s3Logs.status","string")
json.UpdateInt("privilegedModeOverride",123)
json.UpdateString("projectName","string")
json.UpdateInt("queuedTimeoutInMinutesOverride",123)
json.UpdateString("registryCredentialOverride.credential","string")
json.UpdateString("registryCredentialOverride.credentialProvider","string")
json.UpdateInt("reportBuildStatusOverride",123)
json.UpdateString("secondaryArtifactsOverride[0].artifactIdentifier","string")
json.UpdateString("secondaryArtifactsOverride[0].bucketOwnerAccess","string")
json.UpdateInt("secondaryArtifactsOverride[0].encryptionDisabled",123)
json.UpdateString("secondaryArtifactsOverride[0].location","string")
json.UpdateString("secondaryArtifactsOverride[0].name","string")
json.UpdateString("secondaryArtifactsOverride[0].namespaceType","string")
json.UpdateInt("secondaryArtifactsOverride[0].overrideArtifactName",123)
json.UpdateString("secondaryArtifactsOverride[0].packaging","string")
json.UpdateString("secondaryArtifactsOverride[0].path","string")
json.UpdateString("secondaryArtifactsOverride[0].type","string")
json.UpdateString("secondarySourcesOverride[0].auth.resource","string")
json.UpdateString("secondarySourcesOverride[0].auth.type","string")
json.UpdateString("secondarySourcesOverride[0].buildspec","string")
json.UpdateString("secondarySourcesOverride[0].buildStatusConfig.context","string")
json.UpdateString("secondarySourcesOverride[0].buildStatusConfig.targetUrl","string")
json.UpdateInt("secondarySourcesOverride[0].gitCloneDepth",123)
json.UpdateInt("secondarySourcesOverride[0].gitSubmodulesConfig.fetchSubmodules",123)
json.UpdateInt("secondarySourcesOverride[0].insecureSsl",123)
json.UpdateString("secondarySourcesOverride[0].location","string")
json.UpdateInt("secondarySourcesOverride[0].reportBuildStatus",123)
json.UpdateString("secondarySourcesOverride[0].sourceIdentifier","string")
json.UpdateString("secondarySourcesOverride[0].type","string")
json.UpdateString("secondarySourcesVersionOverride[0].sourceIdentifier","string")
json.UpdateString("secondarySourcesVersionOverride[0].sourceVersion","string")
json.UpdateString("serviceRoleOverride","string")
json.UpdateString("sourceAuthOverride.resource","string")
json.UpdateString("sourceAuthOverride.type","string")
json.UpdateString("sourceLocationOverride","string")
json.UpdateString("sourceTypeOverride","string")
json.UpdateString("sourceVersion","string")
json.UpdateInt("timeoutInMinutesOverride",123)

# The JSON request body created by the above code:

# {
#   "artifactsOverride": {
#     "artifactIdentifier": "string",
#     "bucketOwnerAccess": "string",
#     "encryptionDisabled": boolean,
#     "location": "string",
#     "name": "string",
#     "namespaceType": "string",
#     "overrideArtifactName": boolean,
#     "packaging": "string",
#     "path": "string",
#     "type": "string"
#   },
#   "buildspecOverride": "string",
#   "buildStatusConfigOverride": {
#     "context": "string",
#     "targetUrl": "string"
#   },
#   "cacheOverride": {
#     "location": "string",
#     "modes": [
#       "string"
#     ],
#     "type": "string"
#   },
#   "certificateOverride": "string",
#   "computeTypeOverride": "string",
#   "debugSessionEnabled": boolean,
#   "encryptionKeyOverride": "string",
#   "environmentTypeOverride": "string",
#   "environmentVariablesOverride": [
#     {
#       "name": "string",
#       "type": "string",
#       "value": "string"
#     }
#   ],
#   "gitCloneDepthOverride": number,
#   "gitSubmodulesConfigOverride": {
#     "fetchSubmodules": boolean
#   },
#   "idempotencyToken": "string",
#   "imageOverride": "string",
#   "imagePullCredentialsTypeOverride": "string",
#   "insecureSslOverride": boolean,
#   "logsConfigOverride": {
#     "cloudWatchLogs": {
#       "groupName": "string",
#       "status": "string",
#       "streamName": "string"
#     },
#     "s3Logs": {
#       "bucketOwnerAccess": "string",
#       "encryptionDisabled": boolean,
#       "location": "string",
#       "status": "string"
#     }
#   },
#   "privilegedModeOverride": boolean,
#   "projectName": "string",
#   "queuedTimeoutInMinutesOverride": number,
#   "registryCredentialOverride": {
#     "credential": "string",
#     "credentialProvider": "string"
#   },
#   "reportBuildStatusOverride": boolean,
#   "secondaryArtifactsOverride": [
#     {
#       "artifactIdentifier": "string",
#       "bucketOwnerAccess": "string",
#       "encryptionDisabled": boolean,
#       "location": "string",
#       "name": "string",
#       "namespaceType": "string",
#       "overrideArtifactName": boolean,
#       "packaging": "string",
#       "path": "string",
#       "type": "string"
#     }
#   ],
#   "secondarySourcesOverride": [
#     {
#       "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"
#     }
#   ],
#   "secondarySourcesVersionOverride": [
#     {
#       "sourceIdentifier": "string",
#       "sourceVersion": "string"
#     }
#   ],
#   "serviceRoleOverride": "string",
#   "sourceAuthOverride": {
#     "resource": "string",
#     "type": "string"
#   },
#   "sourceLocationOverride": "string",
#   "sourceTypeOverride": "string",
#   "sourceVersion": "string",
#   "timeoutInMinutesOverride": number
# }

rest.AddHeader("Content-Type","application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target","CodeBuild_20161006.StartBuild")

sbRequestBody = chilkat.CkStringBuilder()
json.EmitSb(sbRequestBody)
sbResponseBody = chilkat.CkStringBuilder()
success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody)
if (success != True):
    print(rest.lastErrorText())
    sys.exit()

respStatusCode = rest.get_ResponseStatusCode()
print("response status code = " + str(respStatusCode))
if (respStatusCode != 200):
    print("Response Header:")
    print(rest.responseHeader())
    print("Response Body:")
    print(sbResponseBody.getAsString())
    sys.exit()

jResp = chilkat.CkJsonObject()
jResp.LoadSb(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

Arn = jResp.stringOf("build.arn")
ArtifactIdentifier = jResp.stringOf("build.artifacts.artifactIdentifier")
BucketOwnerAccess = jResp.stringOf("build.artifacts.bucketOwnerAccess")
EncryptionDisabled = jResp.IntOf("build.artifacts.encryptionDisabled")
Location = jResp.stringOf("build.artifacts.location")
Md5sum = jResp.stringOf("build.artifacts.md5sum")
OverrideArtifactName = jResp.IntOf("build.artifacts.overrideArtifactName")
Sha256sum = jResp.stringOf("build.artifacts.sha256sum")
BuildBatchArn = jResp.stringOf("build.buildBatchArn")
BuildComplete = jResp.IntOf("build.buildComplete")
BuildNumber = jResp.IntOf("build.buildNumber")
BuildStatus = jResp.stringOf("build.buildStatus")
CacheLocation = jResp.stringOf("build.cache.location")
v_Type = jResp.stringOf("build.cache.type")
CurrentPhase = jResp.stringOf("build.currentPhase")
SessionEnabled = jResp.IntOf("build.debugSession.sessionEnabled")
SessionTarget = jResp.stringOf("build.debugSession.sessionTarget")
EncryptionKey = jResp.stringOf("build.encryptionKey")
EndTime = jResp.IntOf("build.endTime")
Certificate = jResp.stringOf("build.environment.certificate")
ComputeType = jResp.stringOf("build.environment.computeType")
Image = jResp.stringOf("build.environment.image")
ImagePullCredentialsType = jResp.stringOf("build.environment.imagePullCredentialsType")
PrivilegedMode = jResp.IntOf("build.environment.privilegedMode")
Credential = jResp.stringOf("build.environment.registryCredential.credential")
CredentialProvider = jResp.stringOf("build.environment.registryCredential.credentialProvider")
EnvironmentType = jResp.stringOf("build.environment.type")
Id = jResp.stringOf("build.id")
Initiator = jResp.stringOf("build.initiator")
GroupName = jResp.stringOf("build.logs.cloudWatchLogs.groupName")
Status = jResp.stringOf("build.logs.cloudWatchLogs.status")
StreamName = jResp.stringOf("build.logs.cloudWatchLogs.streamName")
CloudWatchLogsArn = jResp.stringOf("build.logs.cloudWatchLogsArn")
DeepLink = jResp.stringOf("build.logs.deepLink")
LogsGroupName = jResp.stringOf("build.logs.groupName")
S3DeepLink = jResp.stringOf("build.logs.s3DeepLink")
S3LogsBucketOwnerAccess = jResp.stringOf("build.logs.s3Logs.bucketOwnerAccess")
S3LogsEncryptionDisabled = jResp.IntOf("build.logs.s3Logs.encryptionDisabled")
S3LogsLocation = jResp.stringOf("build.logs.s3Logs.location")
S3LogsStatus = jResp.stringOf("build.logs.s3Logs.status")
S3LogsArn = jResp.stringOf("build.logs.s3LogsArn")
LogsStreamName = jResp.stringOf("build.logs.streamName")
NetworkInterfaceId = jResp.stringOf("build.networkInterface.networkInterfaceId")
SubnetId = jResp.stringOf("build.networkInterface.subnetId")
ProjectName = jResp.stringOf("build.projectName")
QueuedTimeoutInMinutes = jResp.IntOf("build.queuedTimeoutInMinutes")
ResolvedSourceVersion = jResp.stringOf("build.resolvedSourceVersion")
ServiceRole = jResp.stringOf("build.serviceRole")
Resource = jResp.stringOf("build.source.auth.resource")
AuthType = jResp.stringOf("build.source.auth.type")
Buildspec = jResp.stringOf("build.source.buildspec")
Context = jResp.stringOf("build.source.buildStatusConfig.context")
TargetUrl = jResp.stringOf("build.source.buildStatusConfig.targetUrl")
GitCloneDepth = jResp.IntOf("build.source.gitCloneDepth")
FetchSubmodules = jResp.IntOf("build.source.gitSubmodulesConfig.fetchSubmodules")
InsecureSsl = jResp.IntOf("build.source.insecureSsl")
SourceLocation = jResp.stringOf("build.source.location")
ReportBuildStatus = jResp.IntOf("build.source.reportBuildStatus")
SourceIdentifier = jResp.stringOf("build.source.sourceIdentifier")
SourceType = jResp.stringOf("build.source.type")
SourceVersion = jResp.stringOf("build.sourceVersion")
StartTime = jResp.IntOf("build.startTime")
TimeoutInMinutes = jResp.IntOf("build.timeoutInMinutes")
VpcId = jResp.stringOf("build.vpcConfig.vpcId")
i = 0
count_i = jResp.SizeOfArray("build.cache.modes")
while i < count_i :
    jResp.put_I(i)
    strVal = jResp.stringOf("build.cache.modes[i]")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.environment.environmentVariables")
while i < count_i :
    jResp.put_I(i)
    name = jResp.stringOf("build.environment.environmentVariables[i].name")
    v_type = jResp.stringOf("build.environment.environmentVariables[i].type")
    value = jResp.stringOf("build.environment.environmentVariables[i].value")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.exportedEnvironmentVariables")
while i < count_i :
    jResp.put_I(i)
    name = jResp.stringOf("build.exportedEnvironmentVariables[i].name")
    value = jResp.stringOf("build.exportedEnvironmentVariables[i].value")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.fileSystemLocations")
while i < count_i :
    jResp.put_I(i)
    identifier = jResp.stringOf("build.fileSystemLocations[i].identifier")
    location = jResp.stringOf("build.fileSystemLocations[i].location")
    mountOptions = jResp.stringOf("build.fileSystemLocations[i].mountOptions")
    mountPoint = jResp.stringOf("build.fileSystemLocations[i].mountPoint")
    v_type = jResp.stringOf("build.fileSystemLocations[i].type")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.phases")
while i < count_i :
    jResp.put_I(i)
    durationInSeconds = jResp.IntOf("build.phases[i].durationInSeconds")
    endTime = jResp.IntOf("build.phases[i].endTime")
    phaseStatus = jResp.stringOf("build.phases[i].phaseStatus")
    phaseType = jResp.stringOf("build.phases[i].phaseType")
    startTime = jResp.IntOf("build.phases[i].startTime")
    j = 0
    count_j = jResp.SizeOfArray("build.phases[i].contexts")
    while j < count_j :
        jResp.put_J(j)
        message = jResp.stringOf("build.phases[i].contexts[j].message")
        statusCode = jResp.stringOf("build.phases[i].contexts[j].statusCode")
        j = j + 1

    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.reportArns")
while i < count_i :
    jResp.put_I(i)
    strVal = jResp.stringOf("build.reportArns[i]")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.secondaryArtifacts")
while i < count_i :
    jResp.put_I(i)
    artifactIdentifier = jResp.stringOf("build.secondaryArtifacts[i].artifactIdentifier")
    bucketOwnerAccess = jResp.stringOf("build.secondaryArtifacts[i].bucketOwnerAccess")
    encryptionDisabled = jResp.IntOf("build.secondaryArtifacts[i].encryptionDisabled")
    location = jResp.stringOf("build.secondaryArtifacts[i].location")
    md5sum = jResp.stringOf("build.secondaryArtifacts[i].md5sum")
    overrideArtifactName = jResp.IntOf("build.secondaryArtifacts[i].overrideArtifactName")
    sha256sum = jResp.stringOf("build.secondaryArtifacts[i].sha256sum")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.secondarySources")
while i < count_i :
    jResp.put_I(i)
    authResource = jResp.stringOf("build.secondarySources[i].auth.resource")
    authType = jResp.stringOf("build.secondarySources[i].auth.type")
    buildspec = jResp.stringOf("build.secondarySources[i].buildspec")
    buildStatusConfigContext = jResp.stringOf("build.secondarySources[i].buildStatusConfig.context")
    buildStatusConfigTargetUrl = jResp.stringOf("build.secondarySources[i].buildStatusConfig.targetUrl")
    gitCloneDepth = jResp.IntOf("build.secondarySources[i].gitCloneDepth")
    gitSubmodulesConfigFetchSubmodules = jResp.IntOf("build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules")
    insecureSsl = jResp.IntOf("build.secondarySources[i].insecureSsl")
    location = jResp.stringOf("build.secondarySources[i].location")
    reportBuildStatus = jResp.IntOf("build.secondarySources[i].reportBuildStatus")
    sourceIdentifier = jResp.stringOf("build.secondarySources[i].sourceIdentifier")
    v_type = jResp.stringOf("build.secondarySources[i].type")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.secondarySourceVersions")
while i < count_i :
    jResp.put_I(i)
    sourceIdentifier = jResp.stringOf("build.secondarySourceVersions[i].sourceIdentifier")
    sourceVersion = jResp.stringOf("build.secondarySourceVersions[i].sourceVersion")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.vpcConfig.securityGroupIds")
while i < count_i :
    jResp.put_I(i)
    strVal = jResp.stringOf("build.vpcConfig.securityGroupIds[i]")
    i = i + 1

i = 0
count_i = jResp.SizeOfArray("build.vpcConfig.subnets")
while i < count_i :
    jResp.put_I(i)
    strVal = jResp.stringOf("build.vpcConfig.subnets[i]")
    i = 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"
#     }
#   }
# }