Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ismailyenigul/d2bf64f7f258a6bc6401f5cf1897e8be to your computer and use it in GitHub Desktop.
Save ismailyenigul/d2bf64f7f258a6bc6401f5cf1897e8be to your computer and use it in GitHub Desktop.
pipeline {
  agent any
     environment {
        AWS_REGION  = 'eu-west-1'
        GITCOMMIT="${env.GIT_COMMIT}"


    }
 //  options { 
 //   ansiColor('xterm')
  // }

stages {

    stage('docker build and push to ecr') {
      
      steps {

       sh(label: 'ECR login and docker push', script:
         '''
         #!/bin/bash
         
           echo "Authenticate with ECR"
            set +x # Don't echo credentials from the login command!
            echo "Building New ECR Image"
            eval $(aws ecr get-login --region "$AWS_REGION" --no-include-email)
            # Enable Debug and Exit immediately 
            set -xe
            docker build  -t 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT} .
            #two push one for master tag other is git commit ID
            docker push 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT}
            docker tag 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:${GITCOMMIT} 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
            docker push 123456789101.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
         '''.stripIndent())


      }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment