diff --git a/jenkins-deploy/jenkinsfiles/api.jenkinsfile b/jenkins-deploy/jenkinsfiles/api.jenkinsfile index cc0846ae0..26e59032f 100644 --- a/jenkins-deploy/jenkinsfiles/api.jenkinsfile +++ b/jenkins-deploy/jenkinsfiles/api.jenkinsfile @@ -6,7 +6,7 @@ pipeline { // } // } environment { - JOB_ENV = "open-im" // namespace + JOB_ENV = "openim-dev" // namespace DEPLOYMENT_NAME = "api" // k8s deploy name CONFIGMAP_NAME = "${DEPLOYMENT_NAME}-conf" // runtime conf JOB_NAME = "${JOB_NAME}" // jenkins job name @@ -19,6 +19,9 @@ pipeline { BASEDIR = "." BUILD_NUM = "${BUILD_NUMBER}" CONF_PATH = "/openim/config/" + + ORGANIZATION_NAME="truongpx396" + SERVICE_NAME_INFRA="open-im-server-k8s-deploy" } parameters { gitParameter( @@ -101,6 +104,7 @@ pipeline { sh """ echo `Build image ...` docker build -t ${JOB_ENV}-${JOB_NAME}:${CommitHash}-${BUILD_NUM} -f ${BASEDIR}/jenkins-deploy/dockerfile/${params.RELEASE_PROJECTS}.Dockerfile . + docker tag ${JOB_ENV}-${JOB_NAME}:${CommitHash}-${BUILD_NUM} ${HARBOR_URL}/${JOB_ENV}-${params.RELEASE_PROJECTS}:${CommitHash}-${BUILD_NUM} echo `Push image ...` @@ -113,6 +117,51 @@ pipeline { } } } + + stage('Prepare to update infra') { + steps { + cleanWs() + git credentialsId: 'GitHub', url: "https://github.com/${ORGANIZATION_NAME}/${SERVICE_NAME_INFRA}" + } + } + + + stage('Update infra') { + steps { + + contentReplace( + configs: [ + fileContentReplaceConfig( + configs: [ + fileContentReplaceItemConfig( + search: "(image: )([*]:[*]-[0-9]+)", + replace: "image: ${HARBOR_URL}/${JOB_ENV}-${params.RELEASE_PROJECTS}:${CommitHash}-${BUILD_NUM}", + matchCount: 1, + verbose: false, + ) + ], + fileEncoding: 'UTF-8', + lineSeparator: 'Unix', + filePath: 'open-im-server/api/deployment.yaml' + ) + ] + ) + + + script { + withCredentials([string(credentialsId: 'GitHub1', variable: 'GITHUB_TOKEN')]) { + sh """ + echo "${GITHUB_TOKEN}" + export BUILD_ID=${CommitHash}-${BUILD_NUM} + git add open-im-server/api/deployment.yaml && git commit -m "Update app image tag to ${CommitHash}-${BUILD_NUM}" + git push -f https://${GITHUB_TOKEN}@github.com/${ORGANIZATION_NAME}/${SERVICE_NAME_INFRA}.git + """ + } + } + } + } + + // stage('Deploy') { // steps { // container ('helm-kubectl') {