|
| 1 | +# CodeBuilder Plugin for Jenkins |
| 2 | + |
| 3 | +This Jenkins plugin dynamically spins up cloud agents using AWS CodeBuild to |
| 4 | +execute jobs. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +Because permission management can be difficult, this plugin assumes you have |
| 9 | +created an AWS CodeBuild project with the necessary IAM roles for the job |
| 10 | +types that you will be running. The project can have any configuration; all |
| 11 | +settings will be overridden by the plugin to provide a build using source |
| 12 | +provided by the Jenkins host. |
| 13 | + |
| 14 | +Once a project is created, you can configure the cloud in Jenkins by adding |
| 15 | +a new cloud and configuring the plugin in `Manage Jenkins > Configure System`. |
| 16 | +After this, builds that match the cloud label will automatically be provisioned |
| 17 | +through AWS CodeBuild. |
| 18 | + |
| 19 | +### Quick Start |
| 20 | + |
| 21 | +#### Creating an AWS CodeBuild Project (Optional) |
| 22 | + |
| 23 | +If you have already setup a project, you can skip this step. Otherwise, if you |
| 24 | +want a quick way to bootstrap configuration, you can use the [AWS CLI][awscli] |
| 25 | +to create an AWS CodeBuild project with bare permissions by running the |
| 26 | +commands below: |
| 27 | + |
| 28 | +```sh |
| 29 | +# Optional command to create a bare IAM role named "jenkins-default" |
| 30 | +aws iam create-role \ |
| 31 | + --role-name jenkins-default \ |
| 32 | + --assume-role-policy-document \ |
| 33 | + '{"Version":"2012-10-17 ","Statement":[{"Effect": "Allow","Principal":{"Service":"codebuild.amazonaws.com"},"Action":"sts:AssumeRole"}]}' |
| 34 | + |
| 35 | +# Create the project named "jenkins-cluster" using our service role |
| 36 | +aws codebuild create-project \ |
| 37 | + --name jenkins-cluster \ |
| 38 | + --service-role jenkins-default \ |
| 39 | + --artifacts type=NO_ARTIFACTS \ |
| 40 | + --environment type=LINUX_CONTAINER,image=aws/codebuild/docker:18.09.0,computeType=BUILD_GENERAL1_SMALL \ |
| 41 | + --source $'type=NO_SOURCE,buildspec=version:0.2\nphases:\n build:\n commands:\n - exit 1' |
| 42 | +``` |
| 43 | + |
| 44 | +#### Configuring the Plugin |
| 45 | + |
| 46 | +In `Manage Jenkins > Configure System` you will find a drop-down to "Add a New |
| 47 | +Cloud": |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +After adding the cloud, you can configure the region, project name, and |
| 52 | +other basic build agent details. Only region and project name are required. |
| 53 | +Credentials can be sourced from your `~/.aws/credentials` file or |
| 54 | +`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables if left |
| 55 | +blank. |
| 56 | + |
| 57 | +Your configuration might look something like this: |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +And that's it, you're all set to trigger new builds on AWS CodeBuild! |
| 62 | + |
| 63 | +[awscli]: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html |
0 commit comments