Prompt
Jenkins pipeline for tests and deployment
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
Here’s a basic Jenkins Declarative Pipeline for running tests and then deploying if tests pass.
Example Jenkinsfile
pipeline {
agent any
environment {
APP_NAME = "my-app"
DEPLOY_SERVER = "your-server.example.com"
DEPLOY_PATH = "/var/www/my-app"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Run Tests') {
steps {
sh 'npm test'
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh """
scp -r dist/* user@${DEPLOY_SERVER}:${DEPLOY_PATH}
"""
}
}
}
post {
success {
echo 'Pipeline completed successfully.'
}
failure {
echo 'Pipeline failed.'
}
always {
cleanWs()
}
}
}
What this does
- Checkout: pulls code from SCM
- Install Dependencies: installs project dependencies
- Run Tests: executes automated tests
- Build: builds the app
- Deploy: deploys only from the
mainbranch - Post actions: logs status and cleans workspace
Common improvements
- Use credentials binding instead of hardcoding server/user info
- Replace
npmcommands with your stack:- Maven:
mvn test,mvn package - Python:
pytest - Java:
gradle test
- Maven:
- Add staging and production deployment stages
- Use SSH keys or Docker/Kubernetes deployment steps depending on environment
If you want, I can give you:
- a Java/Maven Jenkins pipeline,
- a Python pipeline, or
- a Docker/Kubernetes deployment version.