Advertisement

Continuous Integration Work- shop with Jenkins and Git

阅读量:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

install jdk
sudo dnf install java-17-amazon-corretto -y

在这里插入图片描述

enable Jenkins to start automatically once server started ok.

在这里插入图片描述
在这里插入图片描述

add inbound port 8080 for Jenkins:

在这里插入图片描述
在这里插入图片描述

then you can just access the Jenkins UI.
http://your_hostname:8080

在这里插入图片描述

Run the sudo command to display the contents of /var/lib/jenkins/secrets/initialAdminPassword after that, you will be prompted to enter the password.

在这里插入图片描述

create user
install suggest plugin
Create First Admin User

在这里插入图片描述

go to manage Jenkins, then Plugins

在这里插入图片描述

install maven
manage Jenkins, then Tools

在这里插入图片描述

initiate a springboot project

https://start.spring.io/

在这里插入图片描述

import to IDEA:

在这里插入图片描述

add java facker and springboot web

com.github.javafaker
javafaker
1.0.2

org.springframework.boot spring-boot-starter-web 3.2.9 add API:

在这里插入图片描述

add application configuration

在这里插入图片描述
在这里插入图片描述

test the API using Postman. If the application isn't installed, download it initially from Google’s website.

在这里插入图片描述

create a new project at github.com

在这里插入图片描述

配置GitHub Actions 以便更好地了解关于GitHub Actions的信息。你可能有兴趣访问“https://docs.github.com/en/actions/learn-github-actions/understanding-github-
actions”

配置GitHub Actions 以便更好地了解关于GitHub Actions的信息。你可能有兴趣访问“https://docs.github.com/en/actions/learn-github-actions/understanding-github-
actions”

在这里插入图片描述

add yml file in the project folder
.github/workflow/master.yml

在这里插入图片描述

maven.yml:

复制代码
    # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
    # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
    
    # This workflow uses actions that are not certified by GitHub.
    # They are provided by a third-party and are governed by
    # separate terms of service, privacy policy, and support
    # documentation.
    
    name: Java CI with Maven
    
    on:
      push:
    branches: [ "master" ]
      pull_request:
    branches: [ "master" ]
    
    jobs:
      build:
    
    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 with Maven
      run: mvn -B package --file pom.xml
    
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-16/5iZfOPvGHwKaDj97mokMQ20zLrRe.png)
在这里插入图片描述

add Jacoco plugin to make sure the code coverage

复制代码
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.10</version>
    <executions>
    <execution>
    <goals>
    <goal>prepare-agent</goal>
    </goals>
    </execution>
    <!-- attached to Maven test phase -->
    <execution>
    <id>report</id>
    <phase>test</phase>
    <goals>
    <goal>report</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-16/3TvMh4UBcYmajdKXPQpqGke9b81E.png)

Integrate SonarCloud in CI pipeline

login sonarcloud

在这里插入图片描述

carry out a comprehensive analysis of a new project, and then adhere to the necessary procedures. choose the repository accordingly.

在这里插入图片描述

Create an organization

在这里插入图片描述

create a project manually

在这里插入图片描述
在这里插入图片描述

create project

在这里插入图片描述

with Github Actions

在这里插入图片描述
在这里插入图片描述

go to github page.

在这里插入图片描述
在这里插入图片描述

add code part to your Springboot pom file.

复制代码
    <properties>
    		<java.version>17</java.version>
    		<sonar.organization>allenwu-zhiwei</sonar.organization>
    		<sonar.host.url>https://sonarcloud.io/</sonar.host.url>
    	</properties>

update permission on github

在这里插入图片描述

add .github/workflows/sonar.xml

复制代码
    name: SonarCloud
    on:
      push:
    branches:
      - master
      pull_request:
    types: [opened, synchronize, reopened]
    jobs:
      build:
    name: Build and analyze
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: 17
          distribution: 'zulu' # Alternative distribution options are available.
      - name: Cache SonarCloud packages
        uses: actions/cache@v3
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=allenwu-zhiwei_cicd-demo
    
    
    bash
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-16/1ITa2ZePOxN6g7EYFt0cbhsnlGzf.png)

after scanned, you will see below page.

在这里插入图片描述

全部评论 (0)

还没有任何评论哟~