AWS CodeBuild
User Guide (API Version 2016-10-06)

Use AWS CodeBuild with Jenkins

The Jenkins plugin for AWS CodeBuild enables you to integrate AWS CodeBuild with your Jenkins build jobs. Instead of sending your build jobs to Jenkins build nodes, you use the plugin to send your build jobs to AWS CodeBuild. This eliminates the need for you to provision, configure, and manage Jenkins build nodes.

Setting Up Jenkins

For information about setting up Jenkins with the AWS CodeBuild plugin, see the Simplify Your Jenkins Builds with AWS CodeBuild blog post on the AWS DevOps Blog. You can download the AWS CodeBuild Jenkins from https://github.com/awslabs/aws-codebuild-jenkins-plugin.

Installing the Plugin

If you already have a Jenkins set up and would like to only install the AWS CodeBuild plugin, then on your Jenkins instance, in the Plugin Manager, search for "AWS CodeBuild Plugin for Jenkins" .

Using the Plugin

To use AWS CodeBuild with sources from outside of an Amazon VPC

  1. Create a project in the AWS CodeBuild console. For more information, see Create a Build Project (Console).

    • Choose the region where you want to run the build.

    • (Optional) Set the Amazon VPC configuration to allow the AWS CodeBuild build container to access resources in your Amazon VPC.

    • Write down the name of your project. You need it in step 3.

    • (Optional) If your source repository is not natively supported by AWS CodeBuild, you can set Amazon S3 as the input source type for your project.

  2. In the IAMconsole, create an IAM user to be used by the Jenkins plugin.

    • When you create credentials for the user, choose Programmatic Access.

    • Create a policy similar to the following and then attach the policy to your 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"] } ] }
  3. Create a freestyle project in Jenkins.

    • On the Configure page, choose Add build step, and then choose Run build on AWS CodeBuild.

    • Configure your build step.

      • Provide values for Region, Credentials, and Project Name.

      • Choose Use Project source.

      • Save the configuration and run a build from Jenkins.

  4. For Source Code Management, choose how you want to retrieve your source. You might need to install the GitHub plugin (or the Jenkins plugin for your source repository provider) on your Jenkins server.

    • On the Configure page, choose Add build step, and then choose Run build on AWS CodeBuild.

    • Configure your build step.

      • Provide values for Region, Credentials, and Project Name.

      • Choose Use Jenkins source.

      • Save the configuration and run a build from Jenkins.

To use the AWS CodeBuild plugin with the Jenkins Pipeline plugin

  • On your Jenkins pipeline project page, use the snippet generator to generate a pipeline script that adds AWS CodeBuild as a step in your pipeline. It should generate a script similar to this:

    awsCodeBuild projectName: 'project', credentialsType: 'keys', region: 'us-west-2', sourceControlType: 'jenkins'