Chilkat Online Tools

StopBuild Node.js Example

AWS CodeBuild

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node17-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node17-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node17-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node17-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node17-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node17-macosx');
}

function chilkatExample() {

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

    var rest = new chilkat.Rest();
    var success;

    var authAws = new chilkat.AuthAws();
    authAws.AccessKey = "AWS_ACCESS_KEY";
    authAws.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.Region = "us-west-2";
    authAws.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) {
        console.log("ConnectFailReason: " + rest.ConnectFailReason);
        console.log(rest.LastErrorText);
        return;
    }

    // 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

    var json = new chilkat.JsonObject();
    json.UpdateString("id","string");

    // The JSON request body created by the above code:

    // {
    //   "id": "string"
    // }

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

    var sbRequestBody = new chilkat.StringBuilder();
    json.EmitSb(sbRequestBody);
    var sbResponseBody = new chilkat.StringBuilder();
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    var respStatusCode = rest.ResponseStatusCode;
    console.log("response status code = " + respStatusCode);
    if (respStatusCode !== 200) {
        console.log("Response Header:");
        console.log(rest.ResponseHeader);
        console.log("Response Body:");
        console.log(sbResponseBody.GetAsString());
        return;
    }

    var jResp = new chilkat.JsonObject();
    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

    var strVal;
    var name;
    var v_type;
    var value;
    var identifier;
    var location;
    var mountOptions;
    var mountPoint;
    var durationInSeconds;
    var endTime;
    var phaseStatus;
    var phaseType;
    var startTime;
    var j;
    var count_j;
    var message;
    var statusCode;
    var artifactIdentifier;
    var bucketOwnerAccess;
    var encryptionDisabled;
    var md5sum;
    var overrideArtifactName;
    var sha256sum;
    var authResource;
    var authType;
    var buildspec;
    var buildStatusConfigContext;
    var buildStatusConfigTargetUrl;
    var gitCloneDepth;
    var gitSubmodulesConfigFetchSubmodules;
    var insecureSsl;
    var reportBuildStatus;
    var sourceIdentifier;
    var sourceVersion;

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

    i = 0;
    count_i = jResp.SizeOfArray("build.secondaryArtifacts");
    while (i < count_i) {
        jResp.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.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.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.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.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"
    //     }
    //   }
    // }

}

chilkatExample();