×
Find plugins

AWS CodeBuild0.17Minimum Jenkins requirement: 1.642.3ID: aws-codebuild

AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to provision, manage, and scale your own build servers. CodeBuild scales continuously and processes multiple builds concurrently, so your builds are not left waiting in a queue. You can get started quickly by using prepackaged build environments, or you can create custom build environments that use your own build tools. With CodeBuild, you are charged by the minute for the compute resources you use.


The AWS CodeBuild plugin for Jenkins provides a build step for your Jenkins project.

license Build Status

Setup Jenkins

If you already have a Jenkins server on which you want to use the plugin, you can skip to the Plugin Installation section. If not, you can either:

  1. Download Jenkins at jenkins.io and run it directly with java -jar jenkins.war.
  2. Create a Jenkins server on Amazon EC2 with AWS Marketplace.

Plugin Installation

  1. (Recommended) Search for "AWS CodeBuild Plugin for Jenkins" in the Plugin Manager on your Jenkins instance 

  2. Install the plugin manually:

    • Build the AWS CodeBuild Jenkins plugin locally by running mvn install to generate aws-codebuild.hpi in the target directory or

    • Download the latest aws-codebuild.hpi directly from the Jenkins plugin repository

    • In Jenkins, choose Manage Jenkins > Manage Plugins > Advanced > Upload Plugin > Browse (select the aws-codebuild.hpi file) > Upload to install the AWS CodeBuild plugin.

Plugin Usage

Using the AWS CodeBuild plugin with the Jenkins Pipeline plugin

Your CodeBuild project can be configured in a Jenkins Pipeline. as shown below. You can use the snippet generator (click "Pipeline Syntax" on your pipeline project page) to generate the pipeline script that adds CodeBuild as a step in your pipeline. It should generate something like:

awsCodeBuild projectName: 'project', credentialsType: 'keys', awsAccessKey: AWS_ACCESS_KEY_ID, awsSecretKey: AWS_SECRET_ACCESS_KEY, region: 'us-west-2', sourceControlType: 'jenkins'

 

View without Jenkins Blue Ocean plugin:

(Recommended) View with Jenkins Blue Ocean plugin:

 

Using AWS CodeBuild with source available outside of your Amazon VPC

  1. Create Project on the AWS CodeBuild console.
    • Switch to the region you would prefer to run the build in.
    • Make sure to write down the project's name.
  2. Create AWS IAM user to be used by the Jenkins plugin.
    • Create a policy similar to the one following this section.
    • Go to the IAM console, and create a new user.
      • Access type should be: Programmatic Access.
      • Attach policy to user that you created previously.
  3. Create a freestyle project in Jenkins.
    • On the Configure page, choose Add build step > Run build on AWS AWS CodeBuild.
    • Configure your build step.
      • Enter RegionCredentials from the user created previously, and ProjectName.
      • Select Use Project source.
      • Save the configuration and run a build from Jenkins.

Policy sample for IAM user:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:logs:{{region}}:{{awsAccountId}}:log-group:/aws/codebuild/{{projectName}}:*"],
            "Action": ["logs:GetLogEvents"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::{{outputBucket}}/*"],
            "Action": ["s3:GetObject"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:codebuild:{{region}}:{{awsAccountId}}:project/{{projectName}}"],
            "Action": ["codebuild:StartBuild",
                       "codebuild:BatchGetBuilds",
                       "codebuild:BatchGetProjects"]
        }
	]
}

Using AWS CodeBuild with source only available inside of your Amazon VPC

To use AWS CodeBuild inside of a VPC the Jenkins plugin is going to pull the source from your repository inside of your VPC, zip it up and place the source into the Amazon S3 input bucket for the project you specified. To do this we need to make some modifications to the setup above.

  1. Create an Amazon S3 bucket.

  2. Create Project on the AWS CodeBuild console.

    • Use Amazon S3 as the source type.
      • Use the bucket you created previously.
      • Specifiy an Amazon S3 object key.
    • Make sure to write down the project's name.
  3. Create AWS IAM user to be used by the Jenkins plugin.

    • Create a policy similar to the one following this section.
    • Go to the AWS IAM console, and create a new user.
      • Access type should be: Programmatic Access.
      • Attach policy to user that you created previously.
  4. Create a freestyle project in Jenkins.

  • For the Source Code Management make sure to select how you would like to retrieve your source. You may need to install the GitHub Plugin to your Jenkins server.
  • On the Configure page, choose Add build step > Run build on AWS CodeBuild.
  • Configure the build step.
    • Enter RegionCredentials from the user created previously, and Project name.
    • Select Use Jenkins source.
    • Save the configuration and run a build from Jenkins.

Policy sample for IAM user:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:logs:{{region}}:{{awsAccountId}}:log-group:/aws/codebuild/{{projectName}}:*"],
            "Action": ["logs:GetLogEvents"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::{{inputBucket}}"],
            "Action": ["s3:GetBucketVersioning"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::{{inputBucket}}/{{inputObject}}"],
            "Action": ["s3:PutObject"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::{{outputBucket}}/*"],
            "Action": ["s3:GetObject"]
        },
        {
            "Effect": "Allow",
            "Resource": ["arn:aws:codebuild:{{region}}:{{awsAccountId}}:project/{{projectName}}"],
            "Action": ["codebuild:StartBuild",
                       "codebuild:BatchGetBuilds",
                       "codebuild:BatchGetProjects"]
        }
	]
}
ArchivesGet past versions
Labels