Skip to content

Commit

Permalink
Moved checking existing streams before deployment stage and deploymen…
Browse files Browse the repository at this point in the history
…t has a when
  • Loading branch information
COMTOP1 committed Dec 22, 2023
1 parent ae825e5 commit 1be0dd1
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,37 +96,41 @@ pipeline {
}
}

stage('Deploy') {
stages {
stage('Checking existing') {
steps {
script {
final String url = "https://streamer.dev.ystv.co.uk/activeStreams"
final def (String response, String tempCode) =
sh(script: "curl -s -w '~~~%{response_code}' $url", returnStdout: true)
.trim()
.tokenize("~~~")
int code = Integer.parseInt(tempCode)
stage('Checking existing streams') {
steps {
script {
final String url = "https://streamer.dev.ystv.co.uk/activeStreams"
final def (String response, String tempCode) =
sh(script: "curl -s -w '~~~%{response_code}' $url", returnStdout: true)
.trim()
.tokenize("~~~")
int code = Integer.parseInt(tempCode)

echo "HTTP response status code: $code"
echo "HTTP response: $response"
echo "HTTP response status code: $code"
echo "HTTP response: $response"

if (code == 200) {
tempStreams = sh(script: "echo '$response' | jq -M '.streams'", returnStdout: true).trim()
int streams = Integer.parseInt(tempStreams)
if (streams > 0) {
echo "Preexisting active streams: $streams, not deploying"
proceed = "no"
} else {
echo "No preexisting active streams, deploying"
}
}
if (code == 200) {
tempStreams = sh(script: "echo '$response' | jq -M '.streams'", returnStdout: true).trim()
int streams = Integer.parseInt(tempStreams)
if (streams > 0) {
echo "Preexisting active streams: $streams, not deploying"
proceed = "no"
} else {
echo "No preexisting active streams, deploying"
}
}
}
}
}

stage('Deploy') {
when {
expression { proceed == "yes" }
}
stages {
stage('Development') {
when {
expression { env.BRANCH_IS_PRIMARY && proceed == "yes" }
expression { env.BRANCH_IS_PRIMARY }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
Expand All @@ -139,7 +143,7 @@ pipeline {
stage('Production') {
when {
// Checking if it is semantic version release.
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ && proceed == "yes" }
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
Expand Down

0 comments on commit 1be0dd1

Please sign in to comment.