Files
homepage/Jenkinsfile
T
Georgios Jason Efstathiou 90bffcab1e
Gitea/homepage/pipeline/head There was a failure building this commit
another maybe fix
2024-12-26 12:53:52 +01:00

46 lines
1.2 KiB
Groovy

pipeline {
agent any
environment {
REGISTRY = "docker-registry.service.consul"
IMAGE_NAME = "efstajas/homepage"
}
stages {
stage('Docker Build') {
steps {
script {
dockerImage = docker.build("$IMAGE_NAME")
}
}
}
stage('Docker Publish') {
steps {
script {
docker.withRegistry("http://$REGISTRY:4124") {
dockerImage.push("latest")
}
}
}
}
stage('Deploy to Nomad') {
steps {
script {
// Calculate the hash of your Docker image (or your application code)
def imageHash = sh(script: "docker images --no-trunc $IMAGE_NAME | grep latest | awk '{print \$3}'", returnStdout: true).trim()
// Read the jobspec.json file
def jobSpec = readJSON file: 'jobspec.json'
// Write the updated jobspec back to the file
def updatedJobSpec = sh(script: "jq '.meta[\"image_hash\"] = \"$imageHash\"' jobspec.json", returnStdout: true).trim()
sh 'curl -X POST -H "Content-Type: application/json" -d "$updatedJobSpec" http://nomad.service.consul:4646/v1/jobs'
}
}
}
}
}