-
Notifications
You must be signed in to change notification settings - Fork 71
merging feature-2 to main #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4149126
6195045
c067629
91e37e9
b35daca
9a1385a
9485255
124bcdc
6e52445
bdf5f54
8585b3f
2e320f9
c3b13a8
a1ac454
589ee16
a9be0ab
6b0f530
f12423e
492a56f
694897a
205dff3
a7e07cb
a8b4fc8
36b4542
8269ecf
250e4db
0436bb4
50f985a
f4384f8
c6cc021
8f91197
d09295b
a7d5742
b01fb92
df5c472
b3199b3
31ec73c
4b4b752
dd70ba4
5859a71
93544f8
18634ea
0bb4983
2e306a4
272ead3
8044566
4a76fff
8077b7f
249aac8
84ccb0b
f8d8955
d824391
f2bba9c
6e9f4cf
736e8e6
b51bb64
bd96c86
95c2878
e7ab4c2
2f2f3da
aeb3fd4
fb1ccd1
5eeb54f
0d59957
8839044
5862585
0c19871
968339e
fa1b9cd
c069c99
5e5bb48
73ea3ca
bcb0219
ab208f0
87555e8
a86bda7
e31e212
38a5b35
baddbed
aab8aa7
fb22439
74ffb0a
f10566e
103dc24
fae2241
5c8b3cc
7ae80ab
a8242a7
61dcfe6
37d6556
e3789a9
4bf8606
2f433ef
5e8b317
3277314
5fe3eea
5b8da85
8603ef3
da01f5c
c632557
d5f2536
f89f279
be8ba76
b3e0309
7846da7
ceaf502
47070cc
2560df2
7dc7c23
e2ed1a3
ad3bce4
48997ba
97ed8af
7a2ce94
beae017
5feed07
071951b
d0244c0
653a65a
0c52252
fa3fcf9
70b7682
afa01a6
c343f07
3726a5d
7c90bd5
41386f3
c6442cf
f9a66a5
81d88ef
dcb8251
bae2a4d
3931175
b24dd4b
88fb65e
ec2216d
03b5c26
5ad336a
ffb014b
6a50d60
ba110fd
0e64d9a
1bce923
f9b2d4f
ec16d83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| name: Build, Deploy, and Analyze | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: self-hosted | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Install Maven | ||
| - name: Install Maven | ||
| run: | | ||
| sudo apt update | ||
| sudo apt install maven -y | ||
| mvn -v | ||
|
|
||
| # Set up Java | ||
| - name: Set up Java | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| cache: maven | ||
|
|
||
| # Cache Maven dependencies | ||
| - name: Cache Maven dependencies | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.m2 | ||
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-maven- | ||
|
|
||
| # Build the project with Maven | ||
| - name: Build with Maven | ||
| run: mvn clean install | ||
|
|
||
| # Store artifacts with versioning (Before running the .jar) | ||
| - name: Upload Artifacts with Versioning | ||
| uses: actions/upload-artifact@v3 | ||
| with: | ||
| name: my-app-artifact-${{ github.sha }} # Artifact version based on commit SHA | ||
| path: target/*.jar # Path to the built artifact (e.g., JAR file or other build outputs) | ||
|
|
||
| # Run the Spring Boot application in the background | ||
| - name: Run Spring Boot App | ||
| run: mvn spring-boot:run & | ||
|
|
||
| # Wait for the Spring Boot app to fully start | ||
| - name: Wait for Spring Boot App to Start | ||
| run: | | ||
| echo "Waiting for the app to start..." | ||
| sleep 15 # Allow time for the Spring Boot app to fully initialize | ||
| echo "App should now be running." | ||
|
|
||
| # Validate that the application is running | ||
| - name: Validate App is Running | ||
| run: | | ||
| echo "Checking if the app is running..." | ||
| IP_ADDRESS=$(curl -s ifconfig.me) # Fetch public IP address | ||
| PORT=8080 | ||
| RESPONSE=$(curl --write-out "%{http_code}" --silent --output /dev/null http://$IP_ADDRESS:$PORT) | ||
| if [ "$RESPONSE" -eq 200 ]; then | ||
| echo "The app is running successfully at http://$IP_ADDRESS:$PORT!" | ||
| else | ||
| echo "The app failed to start. HTTP response code: $RESPONSE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Display the IP address and port number for accessing the app | ||
| - name: Display IP Address and Port | ||
| run: | | ||
| echo "Fetching the runner's IP address..." | ||
| IP_ADDRESS=$(curl -s ifconfig.me) # This fetches the public IP of the runner | ||
| PORT=8080 | ||
| echo "The app is accessible at: http://$IP_ADDRESS:$PORT" | ||
|
|
||
| # Wait for 3 minutes (180 seconds) | ||
| - name: Wait for 3 minutes | ||
| run: | | ||
| echo "App has been running for 3 minutes. Waiting..." | ||
| sleep 180 # Wait for 3 minutes | ||
|
|
||
| # Stop the Spring Boot app gracefully | ||
| - name: Gracefully Stop Spring Boot App | ||
| run: | | ||
| echo "Stopping the app gracefully..." | ||
| mvn spring-boot:stop | ||
|
|
||
| sonarcloud-analysis: | ||
| runs-on: ubuntu-latest | ||
| needs: build # Ensure the build job runs before sonarcloud-analysis job | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Set up Java | ||
| - name: Set up Java | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| # SonarCloud Analysis (separate job-feature-1) | ||
| - name: SonarCloud Analysis | ||
| env: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| SONAR_ORG: your-organization # Replace with your actual SonarCloud organization | ||
| SONAR_HOST_URL: https://sonarcloud.io | ||
| run: | | ||
| mvn clean verify sonar:sonar \ | ||
| -Dsonar.organization=${{ secrets.SONAR_ORG }} \ | ||
| -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ | ||
| -Dsonar.login=${{ secrets.SONAR_TOKEN }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Build, Deploy, and Analyze | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| workflow_dispatch: # Allow for manual trigger via GitHub UI | ||
|
|
||
| jobs: | ||
| # Call the Java and Maven setup workflow | ||
| java-maven-setup: | ||
| uses: ./.github/workflows/setup-java-maven.yml # Reference to the consolidated Java and Maven setup workflow | ||
|
|
||
| # Call the build and artifact workflow | ||
| build-and-artifact: | ||
| uses: ./.github/workflows/build-and-artifact.yml # Reference to the build workflow | ||
| needs: java-maven-setup # Ensure Java and Maven setup is completed first | ||
|
|
||
| # Call the Spring Boot run and stop workflow | ||
| springboot-run-stop: | ||
| uses: ./.github/workflows/springboot-run-stop.yml # Reference to the Spring Boot workflow | ||
| needs: build-and-artifact # Ensure the build is completed before running Spring Boot | ||
|
|
||
| # Call the SonarCloud analysis workflow | ||
| sonarcloud-analysis: | ||
| uses: ./.github/workflows/sonarcloud-analysis.yml # Reference to the SonarCloud analysis workflow | ||
| needs: build-and-artifact # Ensure the build job is completed before analysis | ||
| secrets: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| SONAR_ORG: ${{ secrets.SONAR_ORG }} | ||
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: SonarCloud Analysis | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| SONAR_TOKEN: # SonarCloud authentication token | ||
| required: true | ||
| SONAR_ORG: # SonarCloud organization | ||
| required: true | ||
| SONAR_HOST_URL: # SonarCloud host URL | ||
| required: true | ||
|
|
||
| jobs: | ||
| sonarcloud-analysis: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Set up Java | ||
| - name: Set up Java | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| # Perform SonarCloud Analysis | ||
| - name: SonarCloud Analysis | ||
| env: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| SONAR_ORG: ${{ secrets.SONAR_ORG }} | ||
| SONAR_HOST_URL: https://sonarcloud.io | ||
| run: | | ||
| mvn clean verify sonar:sonar \ | ||
| -Dsonar.organization=${{ secrets.SONAR_ORG }} \ | ||
| -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ | ||
| -Dsonar.login=${{ secrets.SONAR_TOKEN }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Spring Boot Run and Stop | ||
|
|
||
| on: | ||
| workflow_call: # This workflow can be called from other workflows | ||
|
|
||
| jobs: | ||
| springboot-run-stop: | ||
| runs-on: self-hosted | ||
|
|
||
| steps: | ||
| # Run Spring Boot App | ||
| - name: Run Spring Boot App | ||
| run: mvn spring-boot:run & | ||
|
|
||
| # Wait for the Spring Boot app to fully start | ||
| - name: Wait for Spring Boot App to Start | ||
| run: | | ||
| echo "Waiting for the app to start..." | ||
| sleep 15 | ||
| echo "App should now be running." | ||
|
|
||
| # Validate that the application is running | ||
| - name: Validate App is Running | ||
| run: | | ||
| echo "Checking if the app is running..." | ||
| IP_ADDRESS=$(curl -s ifconfig.me) # Fetch public IP address | ||
| PORT=8080 | ||
| RESPONSE=$(curl --write-out "%{http_code}" --silent --output /dev/null http://$IP_ADDRESS:$PORT) | ||
| if [ "$RESPONSE" -eq 200 ]; then | ||
| echo "The app is running successfully at http://$IP_ADDRESS:$PORT" | ||
| else | ||
| echo "The app failed to start. HTTP response code: $RESPONSE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Wait for 3 minutes (180 seconds) | ||
| - name: Wait for 3 minutes | ||
| run: | | ||
| echo "App has been running for 3 minutes. Waiting..." | ||
| sleep 180 | ||
|
|
||
| # Gracefully Stop Spring Boot App | ||
| - name: Gracefully Stop Spring Boot App | ||
| run: | | ||
| echo "Stopping the app gracefully..." | ||
| mvn spring-boot:stop |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "java.compile.nullAnalysis.mode": "disabled", | ||
| "java.configuration.updateBuildConfiguration": "disabled" | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||
| @Library('Jenkins_library') _ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pipeline { | ||||||||||||||||||||||||||||||
| agent { label 'java' } | ||||||||||||||||||||||||||||||
| // agent any | ||||||||||||||||||||||||||||||
| tools { | ||||||||||||||||||||||||||||||
| jdk 'JDK17' | ||||||||||||||||||||||||||||||
| maven 'maven' | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| stages { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| stage('Checkout') { | ||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||
| checkout scm | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| stage('Build') { | ||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||
| //sh 'mvn clean package -DskipTests=false' | ||||||||||||||||||||||||||||||
| script { | ||||||||||||||||||||||||||||||
| // dir('hello-world-war') { | ||||||||||||||||||||||||||||||
| build 'package' | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, explore the repository structure to locate the Jenkins shared library
find . -type f -name "*.groovy" | head -20Repository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: # Search for the Jenkins_library or shared library references
find . -type d -name "vars" -o -type d -name "shared" -o -type d -name "library" | head -20Repository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: # Look for the Jenkinsfile location and examine it
find . -name "Jenkinsfile" -type fRepository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: git ls-files | head -50Repository: vikas0105/Parcel-service Length of output: 77 🏁 Script executed: # Check if there are any pipeline or Jenkins-related files
git ls-files | grep -i jenkinsRepository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: # Look for any groovy files
git ls-files | grep -i groovyRepository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: # List the top-level structure
ls -laRepository: vikas0105/Parcel-service Length of output: 287 🏁 Script executed: # Check all branches for Jenkinsfile
git branch -aRepository: vikas0105/Parcel-service Length of output: 180 🏁 Script executed: # Search git history for any Jenkinsfile reference
git log --all --pretty=format: --name-only | grep -i jenkinsfile | sort -uRepository: vikas0105/Parcel-service Length of output: 109 🏁 Script executed: # Check git log to see commits
git log --oneline --all | head -20Repository: vikas0105/Parcel-service Length of output: 676 🏁 Script executed: git checkout main
git ls-files | grep -i jenkinsfileRepository: vikas0105/Parcel-service Length of output: 156 🏁 Script executed: # Now read the Jenkinsfile
cat JenkinsfileRepository: vikas0105/Parcel-service Length of output: 111 🏁 Script executed: git checkout coderabbit_6
git ls-files | grep -i jenkinsfileRepository: vikas0105/Parcel-service Length of output: 130 🏁 Script executed: # List all files in this branch
git ls-filesRepository: vikas0105/Parcel-service Length of output: 958 🏁 Script executed: cat -n JenkinsfileRepository: vikas0105/Parcel-service Length of output: 1549 🏁 Script executed: # Check if there's a shared library defined locally
find . -name "vars" -o -name "*library*" -type dRepository: vikas0105/Parcel-service Length of output: 50 🏁 Script executed: # Search for Jenkins_library references or @Library annotations
grep -r "Jenkins_library\|@Library" .Repository: vikas0105/Parcel-service Length of output: 111 🏁 Script executed: # Search for any documentation or comments about the Jenkins_library
grep -r "Jenkins_library" .Repository: vikas0105/Parcel-service Length of output: 111 🏁 Script executed: # Check README for any Jenkins/library documentation
cat README.mdRepository: vikas0105/Parcel-service Length of output: 3243 🏁 Script executed: # Check pom.xml to understand Maven goals and test configuration
cat pom.xml | head -50Repository: vikas0105/Parcel-service Length of output: 1975 Replace the opaque custom Line 24 invokes Either replace with direct Maven invocation (preserving test execution): - script {
- // dir('hello-world-war') {
- build 'package'
- }
+ sh 'mvn clean package -DskipTests=false'Or document the shared library function's contract (Maven goals, test behavior, failure handling). 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and validation between stages. There is no validation that the Build stage succeeded before proceeding to the Run Application stage. If the Maven build fails, the pipeline should halt immediately rather than attempting to run a non-existent or broken application. Add explicit error handling or rely on Jenkins' native stage('Build') {
steps {
- //sh 'mvn clean package -DskipTests=false'
- script {
- // dir('hello-world-war') {
- build 'package'
- }
+ sh 'mvn clean package'
}This makes Maven failures immediately halt the pipeline. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // stage('Archive Artifact') { | ||||||||||||||||||||||||||||||
| // steps { | ||||||||||||||||||||||||||||||
| // archiveArtifacts artifacts: 'target/*.jar', fingerprint: true | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| stage('Run Application') { | ||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||
| sh 'mvn spring-boot:run' | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: The Replace this with one of the following approaches: Option 1: Run application in background (for smoke tests/validation): - sh 'mvn spring-boot:run'
+ sh '''
+ nohup mvn spring-boot:run > app.log 2>&1 &
+ sleep 5
+ if ! curl -f http://localhost:8080/health; then
+ echo "Application failed to start"
+ exit 1
+ fi
+ '''Option 2: Remove this stage (recommended for typical CI/CD builds): - stage('Run Application') {
- steps {
- sh 'mvn spring-boot:run'
- // dir('/var/lib/jenkins/workspace/Parcel_service_feature-1/target') {
- // sh """
- // nohup java -jar simple-parcel-service-app-1.0-SNAPSHOT.jar > app.log 2>&1 &
- //echo "Application started"
- // """
- // }
- }
- }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| // dir('/var/lib/jenkins/workspace/Parcel_service_feature-1/target') { | ||||||||||||||||||||||||||||||
| // sh """ | ||||||||||||||||||||||||||||||
| // nohup java -jar simple-parcel-service-app-1.0-SNAPSHOT.jar > app.log 2>&1 & | ||||||||||||||||||||||||||||||
| //echo "Application started" | ||||||||||||||||||||||||||||||
| // """ | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 50
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 50
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 436
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 50
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 625
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 240
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 1168
🏁 Script executed:
Repository: vikas0105/Parcel-service
Length of output: 3927
Fix SonarCloud env var wiring: use env vars instead of secrets for non-sensitive values.
The
SONAR_ORGandSONAR_HOST_URLare defined in theenvblock but the Maven command references them via${{ secrets.SONAR_ORG }}and${{ secrets.SONAR_HOST_URL }}. Unless those are also created as secrets, these will be empty. Use:- name: SonarCloud Analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_ORG: your-organization # Replace with your actual SonarCloud organization SONAR_HOST_URL: https://sonarcloud.io run: | mvn clean verify sonar:sonar \ - -Dsonar.organization=${{ secrets.SONAR_ORG }} \ - -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ + -Dsonar.organization=$SONAR_ORG \ + -Dsonar.host.url=$SONAR_HOST_URL \ -Dsonar.login=${{ secrets.SONAR_TOKEN }}Also note: the
buildjob runsmvn clean installand thesonarcloud-analysisjob runsmvn clean verify sonar:sonar. Both include test execution, so tests run twice. If build time becomes an issue, consider reusing coverage data from thebuildjob instead of rebuilding.🤖 Prompt for AI Agents