66 lines
2.4 KiB
Plaintext
66 lines
2.4 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
stages {
|
|
stage('Build & Lint') {
|
|
steps {
|
|
script {
|
|
dir('project2') {
|
|
sh "docker build -t quotes-app ."
|
|
echo "🔍 Verificăm sintaxa codului..."
|
|
sh "docker run --rm quotes-app python -m py_compile famousquotes.py"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Run & Extract') {
|
|
steps {
|
|
script {
|
|
dir('project2') {
|
|
sh "docker rm -f quotes-worker || true"
|
|
try {
|
|
// Rulăm containerul pentru a genera fișierul
|
|
sh "docker run --name quotes-worker quotes-app"
|
|
// Copiem rezultatul din container în workspace-ul Jenkins
|
|
sh "docker cp quotes-worker:/app/quote.txt ."
|
|
} catch (e) {
|
|
echo "⚠️ Eroare la execuție."
|
|
} finally {
|
|
sh "docker rm -f quotes-worker || true"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
script {
|
|
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa"
|
|
|
|
def quoteContent = "Fișierul cu citate lipsește."
|
|
if (fileExists('project2/quote.txt')) {
|
|
quoteContent = readFile('project2/quote.txt').trim()
|
|
// Escapăm caracterele speciale pentru a nu strica JSON-ul
|
|
quoteContent = quoteContent.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
|
|
}
|
|
|
|
def resultStatus = currentBuild.result ?: 'SUCCESS'
|
|
def statusEmoji = (resultStatus == 'SUCCESS') ? "✅" : "⚠️"
|
|
def header = "${statusEmoji} **Pipeline Finalizat (Build #${env.BUILD_NUMBER})**"
|
|
|
|
sh """
|
|
cat << 'EOF' > discord_payload.json
|
|
{
|
|
"content": "${header}\\n\\n${quoteContent}"
|
|
}
|
|
EOF
|
|
"""
|
|
|
|
sh "curl -X POST -H 'Content-Type: application/json' --data-binary @discord_payload.json '${discordUrl}'"
|
|
}
|
|
}
|
|
}
|
|
} |