[UPD] - Jenkinsfile with aws credentials test
This commit is contained in:
parent
b9b16c90a0
commit
3ffa9d60c9
1 changed files with 71 additions and 4 deletions
77
Jenkinsfile
vendored
77
Jenkinsfile
vendored
|
|
@ -1,12 +1,79 @@
|
|||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Build Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
docker.build("test-initial-repo:1.0.0", "-f Dockerfile ./src/worker")
|
||||
|
||||
options { skipDefaultCheckout(true) }
|
||||
|
||||
environment {
|
||||
IMAGE_NAME = 'rd.jenkins'
|
||||
IMAGE_TAG = 'caro-v1'
|
||||
CONTAINER_NAME = "${IMAGE_NAME}-container"
|
||||
|
||||
AWS_URL = '231670719202.dkr.ecr.sa-east-1.amazonaws.com'
|
||||
AWS_USER = 'liesa'
|
||||
AWS_REGION = 'sa-east-1'
|
||||
AWS_CREDS_ID = 'aws-jenkins'
|
||||
AWS_REGISTRY = "${AWS_URL}/${AWS_USER}/${IMAGE_NAME}"
|
||||
AWS_IMAGE = "${AWS_REGISTRY}:${IMAGE_TAG}"
|
||||
|
||||
FORGEJO_URL = 'ssh://git@forgejo.test.dev.it.liesa.com.ar'
|
||||
FORGEJO_OWNER = 'carolina.diaz'
|
||||
FORGEJO_REPO = 'test-initial-repo.git'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('AWS ECR Login') {
|
||||
steps {
|
||||
withAWS(credentials: env.AWS_CREDS_ID, region: env.AWS_REGION) {
|
||||
script {
|
||||
def accountId = sh(
|
||||
script: 'set -euo pipefail; aws sts get-caller-identity --query Account --output text',
|
||||
returnStdout: true
|
||||
).trim()
|
||||
env.ECR_REGISTRY = "${accountId}.dkr.ecr.${env.AWS_REGION}.amazonaws.com"
|
||||
}
|
||||
sh '''
|
||||
set -euo pipefail
|
||||
echo "Logging in to AWS ECR: ${ECR_REGISTRY}"
|
||||
aws ecr get-login-password --region "$AWS_REGION" \
|
||||
| docker login --username AWS --password-stdin "$ECR_REGISTRY"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
cleanWs()
|
||||
checkout scm
|
||||
sh '''
|
||||
git rev-parse --short HEAD
|
||||
git status
|
||||
git submodule update --init --recursive
|
||||
git submodule status || true
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Image') {
|
||||
steps {
|
||||
sh "echo ${AWS_REGISTRY}:${IMAGE_TAG}"
|
||||
script {
|
||||
docker.build("${AWS_REGISTRY}:${IMAGE_TAG}", '-f Dockerfile ./src/worker')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push Image') {
|
||||
steps {
|
||||
sh 'docker push "${AWS_REGISTRY}:${IMAGE_TAG}"'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Pull Image') {
|
||||
steps {
|
||||
sh 'docker pull "${AWS_REGISTRY}:${IMAGE_TAG}"'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue