> For the complete documentation index, see [llms.txt](https://chloe-codes1.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chloe-codes1.gitbook.io/til/infra/jenkins/jenkins_build_and_ecr_push.md).

# Jenkins Build and ECR Push

> Docker build with Jenkins and push to Amazon ECR!

\ <br>

### Before getting started

* [Learn about Docker](/til/docker/01_getting_started_with_docker.md)
* [Learn about Amazon ECR](/til/aws/aws-services/amazon_ecr.md)

\ <br>

### Docker Build & Push with Jenkins

<br>

#### 1. Include a `Dockerfile` in the service's source code

#### 2. Configure the `jenkins` server to be able to access ECR

#### 3. Create a deployment Job for the service in `jenkins`, and set the Job to build a new image using the pre-included Dockerfile when executed

#### 4. Build a new docker image on the `jenkins` server and then push the image to ECR

#### 5. Finally, on the test server, pull the new image from ECR, delete the existing container, and create a new container

\ <br>

### Configure Jenkins job example

<br>

#### ex1) Discard old builds

* **Discard old builds**
  * With the settings shown in the example above, Build History is stored for 10 days and a maximum of 20 build histories are kept

    ex)

<br>

#### ex2) Invoke Gradle script

* For Java projects built with Gradle, you can specify Tasks as shown above

<br>

#### ex3) Execute shell

* You can write shell scripts to be executed during the Jenkins job build as shown above

<br>

#### ex4) Post-build Actions

* To save artifacts after the build, you can configure settings as shown above
