u2
This commit is contained in:
@@ -2,58 +2,53 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Initialize & Notify') {
|
||||||
steps {
|
|
||||||
checkout scm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Lint Check') {
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
dir('project2') {
|
// Notificăm imediat ce pornește build-ul
|
||||||
echo "🔍 Verificăm sintaxa Python..."
|
sendDiscordNotification("🚀 **Proiect 2**: Build #${env.BUILD_NUMBER} a început pe ramura develop.")
|
||||||
sh "docker build -t lint-test ."
|
|
||||||
sh "docker run --rm lint-test python -m py_compile famousquotes.py"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build & Run') {
|
stage('Lint & Build') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
dir('project2') {
|
dir('project2') {
|
||||||
echo "🏗️ Construim și rulăm aplicația..."
|
|
||||||
sh "docker build -t quotes-app ."
|
sh "docker build -t quotes-app ."
|
||||||
|
// Linting folosind imaginea construită
|
||||||
/* Folosim --network host pentru a împrumuta conexiunea care a mers la Proiectul 1.
|
sh "docker run --rm quotes-app python -m py_compile famousquotes.py"
|
||||||
Am schimbat API-ul cu unul extrem de simplu (AdviceSlip) care nu dă erori de SSL.
|
|
||||||
*/
|
|
||||||
sh "docker run --rm --network host -e QUOTE_API_URL='https://api.adviceslip.com/advice' quotes-app"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
stage('Run App') {
|
||||||
always {
|
steps {
|
||||||
script {
|
script {
|
||||||
|
try {
|
||||||
|
dir('project2') {
|
||||||
|
// Folosim un API compatibil care returnează cheia 'content'
|
||||||
|
// și --network host pentru a asigura ieșirea spre Discord ulterior
|
||||||
|
sh "docker run --rm --network host -e QUOTE_API_URL='http://api.staging.quotable.io/random' quotes-app"
|
||||||
|
}
|
||||||
|
sendDiscordNotification("✅ **Proiect 2**: Build #${env.BUILD_NUMBER} finalizat cu succes!")
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendDiscordNotification("❌ **Proiect 2**: Build #${env.BUILD_NUMBER} a eșuat la execuție.")
|
||||||
|
error("Build failed: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funcție separată pentru a fi siguri că apelul curl este curat
|
||||||
|
def sendDiscordNotification(String message) {
|
||||||
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa"
|
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa"
|
||||||
|
|
||||||
def result = currentBuild.result ?: 'SUCCESS'
|
|
||||||
def emoji = (result == 'SUCCESS') ? "✅" : "❌"
|
|
||||||
|
|
||||||
echo "🚀 Trimitere notificare către Discord (Status: ${result})..."
|
|
||||||
|
|
||||||
// Folosim metoda cea mai simplă de curl care a mers la Proiectul 1
|
|
||||||
sh """
|
sh """
|
||||||
curl -X POST -H 'Content-Type: application/json' \
|
curl -X POST -H 'Content-Type: application/json' \
|
||||||
-d '{"content": "${emoji} **Proiect 2**: Build #${env.BUILD_NUMBER} s-a finalizat cu status: ${result}"}' \
|
-d '{"content": "${message}"}' \
|
||||||
${discordUrl}
|
${discordUrl}
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user