Skip to content

Instantly share code, notes, and snippets.

@devonartis
Created March 31, 2018 23:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devonartis/e22a5fc0483beabf817d2b52fbc69883 to your computer and use it in GitHub Desktop.
Save devonartis/e22a5fc0483beabf817d2b52fbc69883 to your computer and use it in GitHub Desktop.
Set up a build pipeline with Jenkins and Amazon ECS
node {
def app
def commit_id
environment
{
ECRURL = 'http://xxxxx.dkr.ecr.us-east-1.amazonaws.com/node'
}
stage('Clone repository') {
/* Let's make sure we have the repository cloned to our workspace */
checkout scm
sh "git rev-parse --short HEAD > .git/commit-id"
commit_id = readFile('.git/commit-id').trim()
}
stage('Build image') {
/* This builds the actual image; synonymous to
* docker build on the command line */
app = docker.build("node:${commit_id}", ".")
}
stage('Test Container') {
/* Ideally, we would run a test framework against our image.
* For this example, we're using a Volkswagen-type approach ;-) */
app.withRun(' -p 43567:8080') {
sh 'curl http://localhost:43567'
sh 'wget http://localhost:43567'
}
}
stage('Logging into ECS') {
sh("eval \$(aws ecr get-login --no-include-email --region us-east-1| sed 's|https://||')")
}
stage("Pushing to ECR") {
sh("docker tag node:${commit_id} xxxxx.dkr.ecr.us-east-1.amazonaws.com/node:${commit_id}")
sh("docker push xxxxx.dkr.ecr.us-east-1.amazonaws.com/node:${commit_id}")
}
stage("Rmoving Image") {
sh("docker image rm -f node:${commit_id} ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment