Spring Boot App Failing to Start in Azure DevOps CD Pipeline – Need Insights!

Spring Boot App Failing to Start in Azure DevOps CD Pipeline – Need Insights!

Hey Tech Community!

I’m working on a CI/CD pipeline in Azure DevOps by using Jenkins as my build pipeline to deploy a Spring Boot application on an Azure LinuxVM. The Build Pipeline with Jenkins (using service hook) & deployment to Azure Linux VM was successful initially, but I faced an issue accessing the app via the browser.

Here’s my BUILD Repository which I picked from Online:

After tweaking the script, the pipeline now fails at the application start up stage, throwing the error:

:red_circle: “Spring Boot application failed to start.”
:red_circle: “JAR file not found!” (even though the file is present in /home/pratul/deploy/)

:hammer_and_wrench: Debugging Steps Tried So Far:

:white_check_mark: Verified Java is installed(openjdk version "17.0.13")
:white_check_mark: Checked if the JAR file exists (ls -l confirms it’s there)
:white_check_mark: Tried manually startingthe app: java -jar spring-boot-initial-0.0.1-SNAPSHOT.jar
:white_check_mark: Used netstat -tulnp | grep 8080 to check if the port is in use
:white_check_mark: Killed existing processes on port 8080 before restart
getting this error even though correct path is given with correct permission as -rw in user level

:pushpin: YAML Deployment Script (Relevant Snippet)

yaml Script

  • task: AzureCLI@2
    displayName: ‘Install Java & Start Spring Boot Application’
    inputs:
    azureSubscription: ‘Pay-As-You-Go’
    scriptType: ‘bash’
    scriptLocation: ‘inlineScript’
    inlineScript: |
    VM_IP=‘52.229.163.139’
    USERNAME=‘pratul’
    SSH_KEY_PATH=‘/azagent/revisit-linuxVM_key.pem’
    ssh -i $SSH_KEY_PATH -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $USERNAME@$VM_IP << ‘EOF’

set -ex
DEPLOY_DIR=“/home/$USERNAME/deploy”
JAR_FILE=“spring-boot-initial-0.0.1-SNAPSHOT.jar”

Kill existing process on port 8080

sudo fuser -k 8080/tcp || true

Start the application

nohup java -Xmx512m -Xms256m -jar $DEPLOY_DIR/$JAR_FILE > $DEPLOY_DIR/app.log 2>&1 &
sleep 5

Verify if the process is running

if pgrep -f “$JAR_FILE”; then

echo “:white_check_mark:Spring Boot application started successfully!”

else
echo “:x:ERROR: Spring Boot application failed to start.”
echo “:page_facing_up:App Log:”
cat $DEPLOY_DIR/app.log
exit 1
fi
EOF



Files present in “/home/pratul/deploy”

###Possible Causes?

- File permission issues? (`chmod +x` didn't help)
- Java process starting but failing silently?
- Any missing dependencies?

Has anyone encountered this issue before? What could be causing the failure despite the JAR file being present?
Any insights or debugging tips would be greatly appreciated! 🚀
#AzureDevOps #SpringBoot #CI_CD #DevOps #Azure #Linux #TechHelp #CloudComputing


```For reference here’s the full script:```
trigger:
- none
pool:

vmImage: windows-latest

stages:
- stage: BuildStage

displayName: BuildStage
jobs:

- job: CIJob
displayName: "Jenkins Build JOB"
steps:
- task: JenkinsQueueJob@2
displayName: "Queue Task"
inputs:
serverEndpoint: 'Jenkins-SRC'
jobName: 'revisit-CICD'
isMultibranchJob: true
multibranchPipelineBranch: 'feature/test'
captureConsole: true
capturePipeline: true
isParameterizedJob: false
- task: JenkinsDownloadArtifacts@2
displayName: "Download Artifact Task"
inputs:
jenkinsServerConnection: 'Jenkins-SRC'
jobName: 'revisit-CICD'
saveTo: '$(Build.StagingDirectory)'
jenkinsBuild: 'LastSuccessfulBuild'
- task: PublishBuildArtifacts@1
displayName: "Publish Artifact Task"
inputs:
PathtoPublish: '$(Build.StagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: DeployStage
dependsOn: BuildStage
displayName: DeployStage
jobs:

- deployment: deploytoVM
displayName: 'deploytoVM'
environment:
name: 'MyEnv'
resourceType: VirtualMachine
tags: 'linux'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
displayName: "Download Pipeline Build Artifact"
inputs:
artifactName: drop
targetPath: '$(pipeline.artifact)'
- task: AzureCLI@2
displayName: 'Copy Files to Linux VM'
inputs:
azureSubscription: 'Pay-As-You-Go(52ebb814-d1d8-427b-badb-92e9e2108392)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
# Define variables
ARTIFACT_PATH="/azagent/_work/1/drop/initial/target/spring-boot-initial-0.0.1-SNAPSHOT.jar"
VM_IP='52.229.163.139'
USERNAME='pratul'
SSH_KEY_PATH='/azagent/revisit-linuxVM_key.pem'
ls -l $SSH_KEY_PATH
ls -l $ARTIFACT_PATH
mkdir -p /home/$USERNAME/deploy/
# chmod 664 /home/$USERNAME/deploy/
# Copy JAR file to the Linux VM
scp -i $SSH_KEY_PATH -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $ARTIFACT_PATH $USERNAME@$VM_IP:/home/$USERNAME/deploy/
- task: AzureCLI@2
displayName: 'Install Java & Start Spring Boot Application'
inputs:
azureSubscription: 'Pay-As-You-Go(52ebb814-d1d8-427b-badb-92e9e2108392)'
scriptType: 'bash'

scriptLocation: 'inlineScript'
inlineScript: |
VM_IP='52.229.163.139'
USERNAME='pratul'
SSH_KEY_PATH='/azagent/revisit-linuxVM_key.pem'
ssh -i _KEY_PATH -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $USERNAME@$VM_IP << 'EOF'
set -ex
DEPLOY_DIR="/home/$USERNAME/deploy"
JAR_FILE="spring-boot-initial-0.0.1-SNAPSHOT.jar"
# Kill any existing process on port 8080

sudo fuser -k 8080/tcp || true
# Start the application and log output
nohup java -Xmx512m -Xms256m -jar \$DEPLOY_DIR/\$JAR_FILE > \$DEPLOY_DIR/app.log 2>&1 &
sleep 5
# Check if the process started

if pgrep -f "\$JAR_FILE"; then
echo "✅ Spring Boot application started successfully!"
else

echo "❌ ERROR Spring Boot application failed to start."
echo "📄 App Log:"

cat \$DEPLOY_DIR/app.log

exit 1
fi
EOF

SCREENSHOTS FOR REFERENCE