devops-test/Jenkinsfile

94 lines
2.6 KiB
Groovy

pipeline {
agent any
environment {
APP_NAME = 'devops-test'
VERSION = '1.0.0'
RUNDECK_URL = 'http://rundeck:4440'
RUNDECK_PROJECT = 'devops-test'
}
stages {
stage('Checkout') {
steps {
echo "📦 Cloning repository..."
checkout scm
}
}
stage('Secrets') {
steps {
echo "🔐 Retrieving secrets from Vaultwarden..."
script {
// Mount the scripts directory and run bw
sh '''
if [ -f /opt/scripts/init-bw-session.sh ]; then
echo "Loading Bitwarden session..."
# Note: For production, configure Jenkins credentials properly
echo "Secrets module available"
else
echo "Bitwarden scripts not mounted, skipping..."
fi
'''
}
}
}
stage('Validate') {
steps {
echo "🔍 Validating scripts..."
sh 'ls -la'
sh 'chmod +x app.sh'
sh 'bash -n app.sh'
}
}
stage('Test') {
steps {
echo "🧪 Running tests..."
sh './app.sh'
}
}
stage('Build Info') {
steps {
echo "📊 Build Information:"
echo " App: ${APP_NAME}"
echo " Version: ${VERSION}"
echo " Build: ${BUILD_NUMBER}"
echo " Branch: ${GIT_BRANCH}"
}
}
stage('Deploy via Rundeck') {
when {
branch 'main'
}
steps {
echo "🚀 Triggering Rundeck deployment..."
script {
// Trigger Rundeck job via API
sh '''
echo "Deployment would be triggered here"
echo "Rundeck URL: ${RUNDECK_URL}"
echo "Project: ${RUNDECK_PROJECT}"
# curl -X POST "${RUNDECK_URL}/api/41/job/JOB_ID/run" ...
'''
}
}
}
}
post {
success {
echo "✅ Pipeline completed successfully!"
}
failure {
echo "❌ Pipeline failed!"
}
always {
echo "🏁 Pipeline finished at ${new Date()}"
}
}
}