Reputation: 58
I want to write a script that does the following Pull a repository from git, if repository already exists means running it second then remove the old folder and pull the repository then my repository contain docker-compose file, if docker compose already working then stop it, now docker-compose up -d Same code below:
pipeline {
agent any
stages {
stage('Pull the repo') {
steps {
sh "sudo rm -r devops1"
sh "git clone https://github.com/xyz/devops1.git"
}
}
stage('run it :D'){
steps{
dir('devops1'){
sh "sudo docker-compose down"
sh "sudo docker-compose up -d"
}
}
}
}
}
it fails when repo is not already fetched, i'm unable to place if else condition. Looking for any help or suggestion, Thank you :)
Upvotes: 2
Views: 58
Reputation: 1424
rm -rf
ignores nonexistent directories
docker-compose up
restarts the service, no need to call docker-compose down first
Upvotes: 1