Last active
September 27, 2023 14:00
-
-
Save omegazeng/d9d07a8a1c2bd7bb2cab38e32a12058b to your computer and use it in GitHub Desktop.
Build docker image and push to harbor with jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/omegazeng/d9d07a8a1c2bd7bb2cab38e32a12058b | |
export LC_ALL=en_US.UTF-8 | |
set +x | |
REGISTRY_URL=$1 | |
IMAGE_NAME=$2 | |
BUILD_DATETIME=$(date +%Y%m%d%H%M%S) | |
GIT_COMMIT_SHORT=$(echo ${GIT_COMMIT} | cut -c 1-8) | |
BRANCH=$(echo ${GIT_BRANCH} | sed s#/#-#g) | |
ls -al | |
docker info | |
docker build --rm -t ${REGISTRY_URL}/${IMAGE_NAME}:${BRANCH}-${GIT_COMMIT_SHORT}-${BUILD_DATETIME}-${BUILD_NUMBER} . | |
docker images | grep ${REGISTRY_URL}/${IMAGE_NAME} | |
docker login ${REGISTRY_URL} -u ${REGISTRY_USERNAME} -p ${REGISTRY_PASSWORD} | |
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${BRANCH}-${GIT_COMMIT_SHORT}-${BUILD_DATETIME}-${BUILD_NUMBER} | |
docker system prune --volumes -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment