diff --git a/Jenkinsfile b/Jenkinsfile index c56c833..7e2a887 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,8 @@ pipeline { } environment { + REGISTRY = "10.129.0.7:8085" + REGISTRY_PROJECT = "shagram" IMAGE_NAME = "shagram" DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram" COMPOSE_FILE = "${WORKSPACE}/deploy/shagram/compose.yaml" @@ -27,7 +29,6 @@ pipeline { stage('Detect branch') { steps { script { - env.GIT_BRANCH = sh( script: "git name-rev --name-only --refs=refs/remotes/origin/* HEAD | sed 's#^remotes/##' | head -n1", returnStdout: true @@ -37,19 +38,38 @@ pipeline { } } - stage('Build') { + stage('Build image') { steps { script { env.GIT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() - env.APP_IMAGE = "${IMAGE_NAME}:${env.GIT_SHA}" + // итоговый тег для Harbor + env.APP_IMAGE = "${REGISTRY}/${REGISTRY_PROJECT}/${IMAGE_NAME}:${env.GIT_SHA}" } sh ''' set -eux - docker build -t "$APP_IMAGE" . + # собираем локальный образ без registry + docker build -t "${IMAGE_NAME}:${GIT_SHA}" . ''' } } + stage('Login & Push to Harbor') { + steps { + withCredentials([usernamePassword( + credentialsId: 'harbor-creds', + usernameVariable: 'HARBOR_USER', + passwordVariable: 'HARBOR_PASS' + )]) { + sh ''' + set -eux + echo "$HARBOR_PASS" | docker login "$REGISTRY" -u "$HARBOR_USER" --password-stdin + docker tag "${IMAGE_NAME}:${GIT_SHA}" "${APP_IMAGE}" + docker push "${APP_IMAGE}" + ''' + } + } + } + stage('Test') { steps { sh 'echo "Testing..."' @@ -66,9 +86,10 @@ pipeline { mkdir -p "$DEPLOY_DIR" cat > "$DEPLOY_DIR/.env" <