From 804399e4715504d748312c3a02277d412441a192 Mon Sep 17 00:00:00 2001 From: yykxt Date: Tue, 14 Jun 2022 13:29:09 +0800 Subject: [PATCH 1/5] Update Jenkinsfile-online --- Jenkinsfile-online | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2ca69e7f1..2d7434c99 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -12,11 +12,12 @@ pipeline { environment { DOCKER_CREDENTIAL_ID = 'dockerhub-id' GITHUB_CREDENTIAL_ID = 'github-id' - KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' + KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' + DOCKERHUB_NAMESPACE = 'yykxt' + GITHUB_ACCOUNT = 'yykxt' APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID= 'sonarqube-toker' } stages { From 9fd6894dd8b83c808d301dd8e58fe4c54a4eece3 Mon Sep 17 00:00:00 2001 From: yykxt Date: Tue, 14 Jun 2022 13:39:34 +0800 Subject: [PATCH 2/5] Update Jenkinsfile-online --- Jenkinsfile-online | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2d7434c99..94fcb5316 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -34,6 +34,21 @@ pipeline { } } } + + stage('sonarqube analysis') { + steps { + container ('maven') { + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } + } + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + } stage ('build & push') { steps { From c67cc96f2dccbc824558a6cc1f628faf2c652e11 Mon Sep 17 00:00:00 2001 From: yykxt Date: Wed, 15 Jun 2022 08:33:29 +0800 Subject: [PATCH 3/5] Update Jenkinsfile-online --- Jenkinsfile-online | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 94fcb5316..93f0c5af8 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -40,7 +40,7 @@ pipeline { container ('maven') { withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.login=$SONAR_TOKEN" } } timeout(time: 1, unit: 'HOURS') { From 9df2c5fbf8a19dc1cc4a2252da44d941d47f266e Mon Sep 17 00:00:00 2001 From: yykxt Date: Fri, 15 Aug 2025 10:59:24 +0800 Subject: [PATCH 4/5] 1 --- .github/workflows/ci-cd.yml | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 000000000..717ab0107 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,121 @@ +name: Java CI/CD Pipeline + +on: + push: + branches: [ main, dev ] + pull_request: + branches: [ main, dev ] + +jobs: + #构建和测试 + build-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + #1.安装jdk + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + #2.构建(打包) + - name: Build with Maven + run: mvn -B clean package --file pom.xml + #3.测试 + - name: Run tests + run: mvn test --file pom.xml + #上传测试结果 + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: target/surefire-reports/ + #二、构建并推送镜像到dockerhub + build-and-push-image: + needs: build-and-test + if: github.event_name == 'push' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build application + run: mvn -B clean package --file pom.xml + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: yourusername/your-java-app + tags: | + type=ref,event=branch + type=sha,format=short + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + #三、更新部署配置 + update-deployment-config: + needs: build-and-push-image + runs-on: ubuntu-latest + + steps: + #1.检出部署仓库 + - name: Checkout deployment repository + uses: actions/checkout@v4 + with: + repository: yykxt/CI + token: ${{ secrets.DEPLOYMENT_REPO_TOKEN }} + path: deployment-repo + #2.判断环境 + - name: Determine environment + id: env + run: | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "ENVIRONMENT=production" >> $GITHUB_OUTPUT + else + echo "ENVIRONMENT=staging" >> $GITHUB_OUTPUT + fi + #3.更新部署配置中的镜像标签 + - name: Update image tag in deployment config + run: | + # 提取短SHA作为镜像标签 + IMAGE_TAG=${{ github.sha }} + IMAGE_TAG=${IMAGE_TAG:0:7} + + # 更新Kubernetes部署文件中的镜像标签 + cd deployment-repo + yq eval ".spec.template.spec.containers[0].image = \"yourusername/your-java-app:$IMAGE_TAG\"" -i environments/${{ steps.env.outputs.ENVIRONMENT }}/java-app/deployment.yaml + + - name: Commit and push changes + run: | + cd deployment-repo + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + git add . + git commit -m "Update Java app image to ${{ github.sha }}" + git push From b2ae1a2ed56bed92bebfc43725490f8d8ce3b791 Mon Sep 17 00:00:00 2001 From: yykxt Date: Fri, 15 Aug 2025 11:13:31 +0800 Subject: [PATCH 5/5] Delete .github/workflows directory --- .github/workflows/ci-cd.yml | 121 ------------------------------------ 1 file changed, 121 deletions(-) delete mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 717ab0107..000000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,121 +0,0 @@ -name: Java CI/CD Pipeline - -on: - push: - branches: [ main, dev ] - pull_request: - branches: [ main, dev ] - -jobs: - #构建和测试 - build-and-test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - #1.安装jdk - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - #2.构建(打包) - - name: Build with Maven - run: mvn -B clean package --file pom.xml - #3.测试 - - name: Run tests - run: mvn test --file pom.xml - #上传测试结果 - - name: Upload test results - uses: actions/upload-artifact@v4 - if: always() - with: - name: test-results - path: target/surefire-reports/ - #二、构建并推送镜像到dockerhub - build-and-push-image: - needs: build-and-test - if: github.event_name == 'push' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - - name: Build application - run: mvn -B clean package --file pom.xml - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: yourusername/your-java-app - tags: | - type=ref,event=branch - type=sha,format=short - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - #三、更新部署配置 - update-deployment-config: - needs: build-and-push-image - runs-on: ubuntu-latest - - steps: - #1.检出部署仓库 - - name: Checkout deployment repository - uses: actions/checkout@v4 - with: - repository: yykxt/CI - token: ${{ secrets.DEPLOYMENT_REPO_TOKEN }} - path: deployment-repo - #2.判断环境 - - name: Determine environment - id: env - run: | - if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "ENVIRONMENT=production" >> $GITHUB_OUTPUT - else - echo "ENVIRONMENT=staging" >> $GITHUB_OUTPUT - fi - #3.更新部署配置中的镜像标签 - - name: Update image tag in deployment config - run: | - # 提取短SHA作为镜像标签 - IMAGE_TAG=${{ github.sha }} - IMAGE_TAG=${IMAGE_TAG:0:7} - - # 更新Kubernetes部署文件中的镜像标签 - cd deployment-repo - yq eval ".spec.template.spec.containers[0].image = \"yourusername/your-java-app:$IMAGE_TAG\"" -i environments/${{ steps.env.outputs.ENVIRONMENT }}/java-app/deployment.yaml - - - name: Commit and push changes - run: | - cd deployment-repo - git config --global user.name "GitHub Actions" - git config --global user.email "actions@github.com" - git add . - git commit -m "Update Java app image to ${{ github.sha }}" - git push