Method: Aws::CodeBuild::Client#start_build

Defined in:
lib/aws-sdk-codebuild/client.rb

#start_build(params = {}) ⇒ Types::StartBuildOutput

Starts running a build with the settings defined in the project. These setting include: how to run a build, where to get the source code, which build environment to use, which build commands to run, and where to store the build output.

You can also start a build run by overriding some of the build settings in the project. The overrides only apply for that specific start build request. The settings in the project are unaltered.

Examples:

Request syntax with placeholder values


resp = client.start_build({
  project_name: "NonEmptyString", # required
  secondary_sources_override: [
    {
      type: "CODECOMMIT", # required, accepts CODECOMMIT, CODEPIPELINE, GITHUB, GITLAB, GITLAB_SELF_MANAGED, S3, BITBUCKET, GITHUB_ENTERPRISE, NO_SOURCE
      location: "String",
      git_clone_depth: 1,
      git_submodules_config: {
        fetch_submodules: false, # required
      },
      buildspec: "String",
      auth: {
        type: "OAUTH", # required, accepts OAUTH, CODECONNECTIONS, SECRETS_MANAGER
        resource: "String",
      },
      report_build_status: false,
      build_status_config: {
        context: "String",
        target_url: "String",
      },
      insecure_ssl: false,
      source_identifier: "String",
    },
  ],
  secondary_sources_version_override: [
    {
      source_identifier: "String", # required
      source_version: "String", # required
    },
  ],
  source_version: "String",
  artifacts_override: {
    type: "CODEPIPELINE", # required, accepts CODEPIPELINE, S3, NO_ARTIFACTS
    location: "String",
    path: "String",
    namespace_type: "NONE", # accepts NONE, BUILD_ID
    name: "String",
    packaging: "NONE", # accepts NONE, ZIP
    override_artifact_name: false,
    encryption_disabled: false,
    artifact_identifier: "String",
    bucket_owner_access: "NONE", # accepts NONE, READ_ONLY, FULL
  },
  secondary_artifacts_override: [
    {
      type: "CODEPIPELINE", # required, accepts CODEPIPELINE, S3, NO_ARTIFACTS
      location: "String",
      path: "String",
      namespace_type: "NONE", # accepts NONE, BUILD_ID
      name: "String",
      packaging: "NONE", # accepts NONE, ZIP
      override_artifact_name: false,
      encryption_disabled: false,
      artifact_identifier: "String",
      bucket_owner_access: "NONE", # accepts NONE, READ_ONLY, FULL
    },
  ],
  environment_variables_override: [
    {
      name: "NonEmptyString", # required
      value: "String", # required
      type: "PLAINTEXT", # accepts PLAINTEXT, PARAMETER_STORE, SECRETS_MANAGER
    },
  ],
  source_type_override: "CODECOMMIT", # accepts CODECOMMIT, CODEPIPELINE, GITHUB, GITLAB, GITLAB_SELF_MANAGED, S3, BITBUCKET, GITHUB_ENTERPRISE, NO_SOURCE
  source_location_override: "String",
  source_auth_override: {
    type: "OAUTH", # required, accepts OAUTH, CODECONNECTIONS, SECRETS_MANAGER
    resource: "String",
  },
  git_clone_depth_override: 1,
  git_submodules_config_override: {
    fetch_submodules: false, # required
  },
  buildspec_override: "String",
  insecure_ssl_override: false,
  report_build_status_override: false,
  build_status_config_override: {
    context: "String",
    target_url: "String",
  },
  environment_type_override: "WINDOWS_CONTAINER", # accepts WINDOWS_CONTAINER, LINUX_CONTAINER, LINUX_GPU_CONTAINER, ARM_CONTAINER, WINDOWS_SERVER_2019_CONTAINER, WINDOWS_SERVER_2022_CONTAINER, LINUX_LAMBDA_CONTAINER, ARM_LAMBDA_CONTAINER, LINUX_EC2, ARM_EC2, WINDOWS_EC2, MAC_ARM
  image_override: "NonEmptyString",
  compute_type_override: "BUILD_GENERAL1_SMALL", # accepts BUILD_GENERAL1_SMALL, BUILD_GENERAL1_MEDIUM, BUILD_GENERAL1_LARGE, BUILD_GENERAL1_XLARGE, BUILD_GENERAL1_2XLARGE, BUILD_LAMBDA_1GB, BUILD_LAMBDA_2GB, BUILD_LAMBDA_4GB, BUILD_LAMBDA_8GB, BUILD_LAMBDA_10GB, ATTRIBUTE_BASED_COMPUTE, CUSTOM_INSTANCE_TYPE
  certificate_override: "String",
  cache_override: {
    type: "NO_CACHE", # required, accepts NO_CACHE, S3, LOCAL
    location: "String",
    modes: ["LOCAL_DOCKER_LAYER_CACHE"], # accepts LOCAL_DOCKER_LAYER_CACHE, LOCAL_SOURCE_CACHE, LOCAL_CUSTOM_CACHE
    cache_namespace: "String",
  },
  service_role_override: "NonEmptyString",
  privileged_mode_override: false,
  timeout_in_minutes_override: 1,
  queued_timeout_in_minutes_override: 1,
  encryption_key_override: "NonEmptyString",
  idempotency_token: "String",
  logs_config_override: {
    cloud_watch_logs: {
      status: "ENABLED", # required, accepts ENABLED, DISABLED
      group_name: "String",
      stream_name: "String",
    },
    s3_logs: {
      status: "ENABLED", # required, accepts ENABLED, DISABLED
      location: "String",
      encryption_disabled: false,
      bucket_owner_access: "NONE", # accepts NONE, READ_ONLY, FULL
    },
  },
  registry_credential_override: {
    credential: "NonEmptyString", # required
    credential_provider: "SECRETS_MANAGER", # required, accepts SECRETS_MANAGER
  },
  image_pull_credentials_type_override: "CODEBUILD", # accepts CODEBUILD, SERVICE_ROLE
  debug_session_enabled: false,
  fleet_override: {
    fleet_arn: "String",
  },
  auto_retry_limit_override: 1,
})

Response structure


resp.build.id #=> String
resp.build.arn #=> String
resp.build.build_number #=> Integer
resp.build.start_time #=> Time
resp.build.end_time #=> Time
resp.build.current_phase #=> String
resp.build.build_status #=> String, one of "SUCCEEDED", "FAILED", "FAULT", "TIMED_OUT", "IN_PROGRESS", "STOPPED"
resp.build.source_version #=> String
resp.build.resolved_source_version #=> String
resp.build.project_name #=> String
resp.build.phases #=> Array
resp.build.phases[0].phase_type #=> String, one of "SUBMITTED", "QUEUED", "PROVISIONING", "DOWNLOAD_SOURCE", "INSTALL", "PRE_BUILD", "BUILD", "POST_BUILD", "UPLOAD_ARTIFACTS", "FINALIZING", "COMPLETED"
resp.build.phases[0].phase_status #=> String, one of "SUCCEEDED", "FAILED", "FAULT", "TIMED_OUT", "IN_PROGRESS", "STOPPED"
resp.build.phases[0].start_time #=> Time
resp.build.phases[0].end_time #=> Time
resp.build.phases[0].duration_in_seconds #=> Integer
resp.build.phases[0].contexts #=> Array
resp.build.phases[0].contexts[0].status_code #=> String
resp.build.phases[0].contexts[0].message #=> String
resp.build.source.type #=> String, one of "CODECOMMIT", "CODEPIPELINE", "GITHUB", "GITLAB", "GITLAB_SELF_MANAGED", "S3", "BITBUCKET", "GITHUB_ENTERPRISE", "NO_SOURCE"
resp.build.source.location #=> String
resp.build.source.git_clone_depth #=> Integer
resp.build.source.git_submodules_config.fetch_submodules #=> Boolean
resp.build.source.buildspec #=> String
resp.build.source.auth.type #=> String, one of "OAUTH", "CODECONNECTIONS", "SECRETS_MANAGER"
resp.build.source.auth.resource #=> String
resp.build.source.report_build_status #=> Boolean
resp.build.source.build_status_config.context #=> String
resp.build.source.build_status_config.target_url #=> String
resp.build.source.insecure_ssl #=> Boolean
resp.build.source.source_identifier #=> String
resp.build.secondary_sources #=> Array
resp.build.secondary_sources[0].type #=> String, one of "CODECOMMIT", "CODEPIPELINE", "GITHUB", "GITLAB", "GITLAB_SELF_MANAGED", "S3", "BITBUCKET", "GITHUB_ENTERPRISE", "NO_SOURCE"
resp.build.secondary_sources[0].location #=> String
resp.build.secondary_sources[0].git_clone_depth #=> Integer
resp.build.secondary_sources[0].git_submodules_config.fetch_submodules #=> Boolean
resp.build.secondary_sources[0].buildspec #=> String
resp.build.secondary_sources[0].auth.type #=> String, one of "OAUTH", "CODECONNECTIONS", "SECRETS_MANAGER"
resp.build.secondary_sources[0].auth.resource #=> String
resp.build.secondary_sources[0].report_build_status #=> Boolean
resp.build.secondary_sources[0].build_status_config.context #=> String
resp.build.secondary_sources[0].build_status_config.target_url #=> String
resp.build.secondary_sources[0].insecure_ssl #=> Boolean
resp.build.secondary_sources[0].source_identifier #=> String
resp.build.secondary_source_versions #=> Array
resp.build.secondary_source_versions[0].source_identifier #=> String
resp.build.secondary_source_versions[0].source_version #=> String
resp.build.artifacts.location #=> String
resp.build.artifacts.sha256sum #=> String
resp.build.artifacts.md5sum #=> String
resp.build.artifacts.override_artifact_name #=> Boolean
resp.build.artifacts.encryption_disabled #=> Boolean
resp.build.artifacts.artifact_identifier #=> String
resp.build.artifacts.bucket_owner_access #=> String, one of "NONE", "READ_ONLY", "FULL"
resp.build.secondary_artifacts #=> Array
resp.build.secondary_artifacts[0].location #=> String
resp.build.secondary_artifacts[0].sha256sum #=> String
resp.build.secondary_artifacts[0].md5sum #=> String
resp.build.secondary_artifacts[0].override_artifact_name #=> Boolean
resp.build.secondary_artifacts[0].encryption_disabled #=> Boolean
resp.build.secondary_artifacts[0].artifact_identifier #=> String
resp.build.secondary_artifacts[0].bucket_owner_access #=> String, one of "NONE", "READ_ONLY", "FULL"
resp.build.cache.type #=> String, one of "NO_CACHE", "S3", "LOCAL"
resp.build.cache.location #=> String
resp.build.cache.modes #=> Array
resp.build.cache.modes[0] #=> String, one of "LOCAL_DOCKER_LAYER_CACHE", "LOCAL_SOURCE_CACHE", "LOCAL_CUSTOM_CACHE"
resp.build.cache.cache_namespace #=> String
resp.build.environment.type #=> String, one of "WINDOWS_CONTAINER", "LINUX_CONTAINER", "LINUX_GPU_CONTAINER", "ARM_CONTAINER", "WINDOWS_SERVER_2019_CONTAINER", "WINDOWS_SERVER_2022_CONTAINER", "LINUX_LAMBDA_CONTAINER", "ARM_LAMBDA_CONTAINER", "LINUX_EC2", "ARM_EC2", "WINDOWS_EC2", "MAC_ARM"
resp.build.environment.image #=> String
resp.build.environment.compute_type #=> String, one of "BUILD_GENERAL1_SMALL", "BUILD_GENERAL1_MEDIUM", "BUILD_GENERAL1_LARGE", "BUILD_GENERAL1_XLARGE", "BUILD_GENERAL1_2XLARGE", "BUILD_LAMBDA_1GB", "BUILD_LAMBDA_2GB", "BUILD_LAMBDA_4GB", "BUILD_LAMBDA_8GB", "BUILD_LAMBDA_10GB", "ATTRIBUTE_BASED_COMPUTE", "CUSTOM_INSTANCE_TYPE"
resp.build.environment.compute_configuration.v_cpu #=> Integer
resp.build.environment.compute_configuration.memory #=> Integer
resp.build.environment.compute_configuration.disk #=> Integer
resp.build.environment.compute_configuration.machine_type #=> String, one of "GENERAL", "NVME"
resp.build.environment.compute_configuration.instance_type #=> String
resp.build.environment.fleet.fleet_arn #=> String
resp.build.environment.environment_variables #=> Array
resp.build.environment.environment_variables[0].name #=> String
resp.build.environment.environment_variables[0].value #=> String
resp.build.environment.environment_variables[0].type #=> String, one of "PLAINTEXT", "PARAMETER_STORE", "SECRETS_MANAGER"
resp.build.environment.privileged_mode #=> Boolean
resp.build.environment.certificate #=> String
resp.build.environment.registry_credential.credential #=> String
resp.build.environment.registry_credential.credential_provider #=> String, one of "SECRETS_MANAGER"
resp.build.environment.image_pull_credentials_type #=> String, one of "CODEBUILD", "SERVICE_ROLE"
resp.build.environment.docker_server.compute_type #=> String, one of "BUILD_GENERAL1_SMALL", "BUILD_GENERAL1_MEDIUM", "BUILD_GENERAL1_LARGE", "BUILD_GENERAL1_XLARGE", "BUILD_GENERAL1_2XLARGE", "BUILD_LAMBDA_1GB", "BUILD_LAMBDA_2GB", "BUILD_LAMBDA_4GB", "BUILD_LAMBDA_8GB", "BUILD_LAMBDA_10GB", "ATTRIBUTE_BASED_COMPUTE", "CUSTOM_INSTANCE_TYPE"
resp.build.environment.docker_server.security_group_ids #=> Array
resp.build.environment.docker_server.security_group_ids[0] #=> String
resp.build.environment.docker_server.status.status #=> String
resp.build.environment.docker_server.status.message #=> String
resp.build.service_role #=> String
resp.build.logs.group_name #=> String
resp.build.logs.stream_name #=> String
resp.build.logs.deep_link #=> String
resp.build.logs.s3_deep_link #=> String
resp.build.logs.cloud_watch_logs_arn #=> String
resp.build.logs.s3_logs_arn #=> String
resp.build.logs.cloud_watch_logs.status #=> String, one of "ENABLED", "DISABLED"
resp.build.logs.cloud_watch_logs.group_name #=> String
resp.build.logs.cloud_watch_logs.stream_name #=> String
resp.build.logs.s3_logs.status #=> String, one of "ENABLED", "DISABLED"
resp.build.logs.s3_logs.location #=> String
resp.build.logs.s3_logs.encryption_disabled #=> Boolean
resp.build.logs.s3_logs.bucket_owner_access #=> String, one of "NONE", "READ_ONLY", "FULL"
resp.build.timeout_in_minutes #=> Integer
resp.build.queued_timeout_in_minutes #=> Integer
resp.build.build_complete #=> Boolean
resp.build.initiator #=> String
resp.build.vpc_config.vpc_id #=> String
resp.build.vpc_config.subnets #=> Array
resp.build.vpc_config.subnets[0] #=> String
resp.build.vpc_config.security_group_ids #=> Array
resp.build.vpc_config.security_group_ids[0] #=> String
resp.build.network_interface.subnet_id #=> String
resp.build.network_interface.network_interface_id #=> String
resp.build.encryption_key #=> String
resp.build.exported_environment_variables #=> Array
resp.build.exported_environment_variables[0].name #=> String
resp.build.exported_environment_variables[0].value #=> String
resp.build.report_arns #=> Array
resp.build.report_arns[0] #=> String
resp.build.file_system_locations #=> Array
resp.build.file_system_locations[0].type #=> String, one of "EFS"
resp.build.file_system_locations[0].location #=> String
resp.build.file_system_locations[0].mount_point #=> String
resp.build.file_system_locations[0].identifier #=> String
resp.build.file_system_locations[0].mount_options #=> String
resp.build.debug_session.session_enabled #=> Boolean
resp.build.debug_session.session_target #=> String
resp.build.build_batch_arn #=> String
resp.build.auto_retry_config.auto_retry_limit #=> Integer
resp.build.auto_retry_config.auto_retry_number #=> Integer
resp.build.auto_retry_config.next_auto_retry #=> String
resp.build.auto_retry_config.previous_auto_retry #=> String

Parameters:

  • params (Hash) (defaults to: {})

    ({})

Options Hash (params):

  • :project_name (required, String)

    The name of the CodeBuild build project to start running a build.

  • :secondary_sources_override (Array<Types::ProjectSource>)

    An array of ProjectSource objects.

  • :secondary_sources_version_override (Array<Types::ProjectSourceVersion>)

    An array of ProjectSourceVersion objects that specify one or more versions of the project’s secondary sources to be used for this build only.

  • :source_version (String)

    The version of the build input to be built, for this build only. If not specified, the latest version is used. If specified, the contents depends on the source provider:

    CodeCommit

    : The commit ID, branch, or Git tag to use.

    GitHub

    : The commit ID, pull request ID, branch name, or tag name that

    corresponds to the version of the source code you want to build. If
    a pull request ID is specified, it must use the format
    `pr/pull-request-ID` (for example `pr/25`). If a branch name is
    specified, the branch's HEAD commit ID is used. If not specified,
    the default branch's HEAD commit ID is used.
    

    GitLab

    : The commit ID, branch, or Git tag to use.

    Bitbucket

    : The commit ID, branch name, or tag name that corresponds to the

    version of the source code you want to build. If a branch name is
    specified, the branch's HEAD commit ID is used. If not specified,
    the default branch's HEAD commit ID is used.
    

    Amazon S3

    : The version ID of the object that represents the build input ZIP

    file to use.
    

    If sourceVersion is specified at the project level, then this sourceVersion (at the build level) takes precedence.

    For more information, see [Source Version Sample with CodeBuild][1] in the *CodeBuild User Guide*.

    [1]: docs.aws.amazon.com/codebuild/latest/userguide/sample-source-version.html

  • :artifacts_override (Types::ProjectArtifacts)

    Build output artifact settings that override, for this build only, the latest ones already defined in the build project.

  • :secondary_artifacts_override (Array<Types::ProjectArtifacts>)

    An array of ProjectArtifacts objects.

  • :environment_variables_override (Array<Types::EnvironmentVariable>)

    A set of environment variables that overrides, for this build only, the latest ones already defined in the build project.

  • :source_type_override (String)

    A source input type, for this build, that overrides the source input defined in the build project.

  • :source_location_override (String)

    A location that overrides, for this build, the source location for the one defined in the build project.

  • :source_auth_override (Types::SourceAuth)

    An authorization type for this build that overrides the one defined in the build project. This override applies only if the build project’s source is BitBucket, GitHub, GitLab, or GitLab Self Managed.

  • :git_clone_depth_override (Integer)

    The user-defined depth of history, with a minimum value of 0, that overrides, for this build only, any previous depth of history defined in the build project.

  • :git_submodules_config_override (Types::GitSubmodulesConfig)

    Information about the Git submodules configuration for this build of an CodeBuild build project.

  • :buildspec_override (String)

    A buildspec file declaration that overrides the latest one defined in the build project, for this build only. The buildspec defined on the project is not changed.

    If this value is set, it can be either an inline buildspec definition, the path to an alternate buildspec file relative to the value of the built-in CODEBUILD_SRC_DIR environment variable, or the path to an S3 bucket. The bucket must be in the same Amazon Web Services Region as the build project. Specify the buildspec file using its ARN (for example, arn:aws:s3:::my-codebuild-sample2/buildspec.yml). If this value is not provided or is set to an empty string, the source code must contain a buildspec file in its root directory. For more information, see [Buildspec File Name and Storage Location][1].

    <note markdown=“1”> Since this property allows you to change the build commands that will run in the container, you should note that an IAM principal with the ability to call this API and set this parameter can override the default settings. Moreover, we encourage that you use a trustworthy buildspec location like a file in your source repository or a Amazon S3 bucket. Alternatively, you can restrict overrides to the buildspec by using a condition key: [Prevent unauthorized modifications to project buildspec][2].

    </note>
    

    [1]: docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-name-storage [2]: docs.aws.amazon.com/codebuild/latest/userguide/action-context-keys.html#action-context-keys-example-overridebuildspec.html

  • :insecure_ssl_override (Boolean)

    Enable this flag to override the insecure SSL setting that is specified in the build project. The insecure SSL setting determines whether to ignore SSL warnings while connecting to the project source code. This override applies only if the build’s source is GitHub Enterprise.

  • :report_build_status_override (Boolean)

    Set to true to report to your source provider the status of a build’s start and completion. If you use this option with a source provider other than GitHub, GitHub Enterprise, GitLab, GitLab Self Managed, or Bitbucket, an invalidInputException is thrown.

    To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, see [Source provider access][1] in the *CodeBuild User Guide*.

    <note markdown=“1”> The status of a build triggered by a webhook is always reported to your source provider.

    </note>
    

    [1]: docs.aws.amazon.com/codebuild/latest/userguide/access-tokens.html

  • :build_status_config_override (Types::BuildStatusConfig)

    Contains information that defines how the build project reports the build status to the source provider. This option is only used when the source provider is GITHUB, GITHUB_ENTERPRISE, or BITBUCKET.

  • :environment_type_override (String)

    A container type for this build that overrides the one specified in the build project.

  • :image_override (String)

    The name of an image for this build that overrides the one specified in the build project.

  • :compute_type_override (String)

    The name of a compute type for this build that overrides the one specified in the build project.

  • :certificate_override (String)

    The name of a certificate for this build that overrides the one specified in the build project.

  • :cache_override (Types::ProjectCache)

    A ProjectCache object specified for this build that overrides the one defined in the build project.

  • :service_role_override (String)

    The name of a service role for this build that overrides the one specified in the build project.

  • :privileged_mode_override (Boolean)

    Enable this flag to override privileged mode in the build project.

  • :timeout_in_minutes_override (Integer)

    The number of build timeout minutes, from 5 to 2160 (36 hours), that overrides, for this build only, the latest setting already defined in the build project.

  • :queued_timeout_in_minutes_override (Integer)

    The number of minutes a build is allowed to be queued before it times out.

  • :encryption_key_override (String)

    The Key Management Service customer master key (CMK) that overrides the one specified in the build project. The CMK key encrypts the build output artifacts.

    <note markdown=“1”> You can use a cross-account KMS key to encrypt the build output artifacts if your service role has permission to that key.

    </note>
    

    You can specify either the Amazon Resource Name (ARN) of the CMK or, if available, the CMK’s alias (using the format ‘alias/<alias-name>`).

  • :idempotency_token (String)

    A unique, case sensitive identifier you provide to ensure the idempotency of the StartBuild request. The token is included in the StartBuild request and is valid for 5 minutes. If you repeat the StartBuild request with the same token, but change a parameter, CodeBuild returns a parameter mismatch error.

  • :logs_config_override (Types::LogsConfig)

    Log settings for this build that override the log settings defined in the build project.

  • :registry_credential_override (Types::RegistryCredential)

    The credentials for access to a private registry.

  • :image_pull_credentials_type_override (String)

    The type of credentials CodeBuild uses to pull images in your build. There are two valid values:

    CODEBUILD

    : Specifies that CodeBuild uses its own credentials. This requires

    that you modify your ECR repository policy to trust CodeBuild's
    service principal.
    

    SERVICE_ROLE

    : Specifies that CodeBuild uses your build project’s service role.

    When using a cross-account or private registry image, you must use SERVICE_ROLE credentials. When using an CodeBuild curated image, you must use CODEBUILD credentials.

  • :debug_session_enabled (Boolean)

    Specifies if session debugging is enabled for this build. For more information, see [Viewing a running build in Session Manager][1].

    [1]: docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html

  • :fleet_override (Types::ProjectFleet)

    A ProjectFleet object specified for this build that overrides the one defined in the build project.

  • :auto_retry_limit_override (Integer)

    The maximum number of additional automatic retries after a failed build. For example, if the auto-retry limit is set to 2, CodeBuild will call the RetryBuild API to automatically retry your build for up to 2 additional times.

Returns:

See Also:



4808
4809
4810
4811
# File 'lib/aws-sdk-codebuild/client.rb', line 4808

def start_build(params = {}, options = {})
  req = build_request(:start_build, params)
  req.send_request(options)
end