refactor: slim pipeline to test + build/push only
Remove Checkout stage (multibranch auto-checks out), Bump Helm Chart, and Commit & Push stages. Drop tools container and chart env vars. Image tag is now branch-random8 (e.g. main-a1b2c3d4).
This commit is contained in:
78
Jenkinsfile
vendored
78
Jenkinsfile
vendored
@@ -21,12 +21,6 @@ spec:
|
|||||||
value: ""
|
value: ""
|
||||||
args:
|
args:
|
||||||
- --insecure-registry=harbor-core.harbor.svc.cluster.local
|
- --insecure-registry=harbor-core.harbor.svc.cluster.local
|
||||||
- name: tools
|
|
||||||
image: alpine/git
|
|
||||||
command:
|
|
||||||
- sleep
|
|
||||||
args:
|
|
||||||
- infinity
|
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,17 +31,9 @@ spec:
|
|||||||
HARBOR_PROJECT = 'library'
|
HARBOR_PROJECT = 'library'
|
||||||
IMAGE = "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${APP_NAME}"
|
IMAGE = "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${APP_NAME}"
|
||||||
DOCKER_HOST = 'tcp://localhost:2375'
|
DOCKER_HOST = 'tcp://localhost:2375'
|
||||||
CHART_FILE = 'manifest/helm/Chart.yaml'
|
|
||||||
VALUES_FILE = 'manifest/helm/values.yaml'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
|
||||||
steps {
|
|
||||||
checkout scm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Install & Test') {
|
stage('Install & Test') {
|
||||||
steps {
|
steps {
|
||||||
container('node') {
|
container('node') {
|
||||||
@@ -59,59 +45,23 @@ spec:
|
|||||||
|
|
||||||
stage('Build & Push Image') {
|
stage('Build & Push Image') {
|
||||||
steps {
|
steps {
|
||||||
container('docker') {
|
script {
|
||||||
withCredentials([usernamePassword(
|
def imageTag = "${env.BRANCH_NAME.replaceAll('/', '-')}-${UUID.randomUUID().toString().take(8)}"
|
||||||
credentialsId: 'harbor-credentials',
|
container('docker') {
|
||||||
usernameVariable: 'HARBOR_USER',
|
withCredentials([usernamePassword(
|
||||||
passwordVariable: 'HARBOR_PASS'
|
credentialsId: 'harbor-credentials',
|
||||||
)]) {
|
usernameVariable: 'HARBOR_USER',
|
||||||
sh """
|
passwordVariable: 'HARBOR_PASS'
|
||||||
docker login ${HARBOR_REGISTRY} -u \${HARBOR_USER} -p \${HARBOR_PASS}
|
)]) {
|
||||||
docker build -t ${IMAGE}:${BUILD_NUMBER} .
|
sh """
|
||||||
docker push ${IMAGE}:${BUILD_NUMBER}
|
docker login ${HARBOR_REGISTRY} -u \${HARBOR_USER} -p \${HARBOR_PASS}
|
||||||
"""
|
docker build -t ${IMAGE}:${imageTag} .
|
||||||
}
|
docker push ${IMAGE}:${imageTag}
|
||||||
}
|
"""
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
stage('Bump Helm Chart') {
|
|
||||||
steps {
|
|
||||||
container('tools') {
|
|
||||||
script {
|
|
||||||
def content = readFile(CHART_FILE)
|
|
||||||
def matcher = content =~ /version:\s+(\d+)\.(\d+)\.(\d+)/
|
|
||||||
def newVersion = "${matcher[0][1]}.${matcher[0][2]}.${matcher[0][3].toInteger() + 1}"
|
|
||||||
sh "sed -i 's/^version: .*/version: ${newVersion}/' ${CHART_FILE}"
|
|
||||||
sh "sed -i 's/^appVersion: .*/appVersion: \"${BUILD_NUMBER}\"/' ${CHART_FILE}"
|
|
||||||
sh "sed -i 's/^ tag: .*/ tag: ${BUILD_NUMBER}/' ${VALUES_FILE}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Commit & Push') {
|
|
||||||
steps {
|
|
||||||
container('tools') {
|
|
||||||
withCredentials([usernamePassword(
|
|
||||||
credentialsId: 'gitea-credentials',
|
|
||||||
usernameVariable: 'GIT_USER',
|
|
||||||
passwordVariable: 'GIT_PASS'
|
|
||||||
)]) {
|
|
||||||
sh """
|
|
||||||
git config user.email "jenkins@fireflylab.local"
|
|
||||||
git config user.name "Jenkins"
|
|
||||||
git add ${CHART_FILE} ${VALUES_FILE}
|
|
||||||
git commit -m "ci: bump tictactoe chart to build ${BUILD_NUMBER}"
|
|
||||||
REMOTE_URL=\$(git remote get-url origin)
|
|
||||||
AUTH_URL=\$(echo \$REMOTE_URL | sed "s|https://|https://\${GIT_USER}:\${GIT_PASS}@|")
|
|
||||||
BRANCH=\$(git rev-parse --abbrev-ref HEAD)
|
|
||||||
git push \$AUTH_URL HEAD:\$BRANCH
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user