Cannot host Spring web app war on Tomcat using Jenkins plugin

Can you help me to deploy my project to Tomcat container using Jenkins? In build step I use script file buildscript-no-launch.bash:
#!/bin/sh

echo Removing old resources...
cd Maitinimas-back/src/main/resources/public
rm -r -f ./*
echo "Old resources removed."

echo Building react app...
cd ../../../../../Maitinimas-front/

# Check if node_modules/ exists, if not run npm install
if [ ! -d "node_modules" ]; then
echo "node_modules not found. Running npm install..."
npm install
if [ $? -ne 0 ]; then
echo "npm install failed. Exiting."
exit 1
fi
else
echo "node_modules exists. Skipping npm install."
fi

# Run npm build and check for errors
if npm run build | grep "Failed\|failed\|error\|Error\|not found"
then echo Npm build failed, try npm install first
exit 1
else
echo Npm build completed
fi

echo Copying build to target...
cd ../Maitinimas-back/src/main/resources/public/
cp -r ../../../../../Maitinimas-front/build/* .
echo "Build copied."

echo Maven clean package...
cd ../../../../
mvn clean package -DskipTests
#!/bin/sh

echo Removing old resources...
cd Maitinimas-back/src/main/resources/public
rm -r -f ./*
echo "Old resources removed."

echo Building react app...
cd ../../../../../Maitinimas-front/

# Check if node_modules/ exists, if not run npm install
if [ ! -d "node_modules" ]; then
echo "node_modules not found. Running npm install..."
npm install
if [ $? -ne 0 ]; then
echo "npm install failed. Exiting."
exit 1
fi
else
echo "node_modules exists. Skipping npm install."
fi

# Run npm build and check for errors
if npm run build | grep "Failed\|failed\|error\|Error\|not found"
then echo Npm build failed, try npm install first
exit 1
else
echo Npm build completed
fi

echo Copying build to target...
cd ../Maitinimas-back/src/main/resources/public/
cp -r ../../../../../Maitinimas-front/build/* .
echo "Build copied."

echo Maven clean package...
cd ../../../../
mvn clean package -DskipTests
This one works well. But then I use post-build step Deploy war/ear to a container
No description
6 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Tomasm21! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Tomasm21
Tomasm21OP2mo ago
It gets deployed:
No description
Tomasm21
Tomasm21OP2mo ago
But once I open it then it's not found:
No description
Tomasm21
Tomasm21OP2mo ago
frontend homepage is /Maitinimas But http://localhost:2020/Maitinimas-0.0.1/Maitinimas and http://localhost:2020/Maitinimas also does not work. In application.properties I have server.servlet.context-path=/Maitinimas. -------------------------------- But if in the build bash file I use embedded tomcat:
//.....
echo Copying build to target...
cd ../Maitinimas-back/src/main/resources/public/
cp -r ../../../../../Maitinimas-front/build/* .
echo "Build copied."

echo Maven clean package...
cd ../../../../
mvn clean package -DskipTests

#echo Starting tomcat on port 8081...
mvn org.codehaus.cargo:cargo-maven2-plugin:1.7.7:run -Dcargo.maven.containerId=tomcat9x -Dcargo.servlet.port=8081 -Dcargo.maven.containerUrl=https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/9.0.40/tomcat-9.0.40.zip
//.....
echo Copying build to target...
cd ../Maitinimas-back/src/main/resources/public/
cp -r ../../../../../Maitinimas-front/build/* .
echo "Build copied."

echo Maven clean package...
cd ../../../../
mvn clean package -DskipTests

#echo Starting tomcat on port 8081...
mvn org.codehaus.cargo:cargo-maven2-plugin:1.7.7:run -Dcargo.maven.containerId=tomcat9x -Dcargo.servlet.port=8081 -Dcargo.maven.containerUrl=https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/9.0.40/tomcat-9.0.40.zip
Then the tomcat server starts in the terminal and I can succesfully load my web app on http://localhost:8081/Maitinimas I have installed Apache Tomcat/9.0.95 on my PC on Windows. And it's really strange that Jenkins post-build step is not working as it should. I don't know why. Maybe the step works because the project is passed to the Tomcat. And the app is in the list. But it can't be found. I don't know particular reason.
Tomasm21
Tomasm21OP2mo ago
Also checkout Jenkins console output:
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server