Skip to content

Commit 2c53e84

Browse files
feat: improvments to build job (#345)
1 parent 886abff commit 2c53e84

File tree

6 files changed

+142
-18
lines changed

6 files changed

+142
-18
lines changed

Dockerfile-deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ENV PNPM_HOME="/pnpm"
33
ENV PATH="$PNPM_HOME:$PATH"
44
RUN corepack enable
55

6-
RUN apt-get update && apt-get install -y jq
6+
RUN apt-get update && apt-get install -y jq && apt-get install -y curl
77

88
COPY . /app
99
WORKDIR /app

Jenkinsfile.build

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
pipeline {
2-
agent any
2+
agent {
3+
dockerfile {
4+
filename 'Dockerfile-deploy'
5+
reuseNode true
6+
}
7+
}
8+
9+
environment {
10+
PROJECT_NAME = 'angular-love-client'
11+
}
312

413
stages {
5-
stage('Trigger Builds') {
14+
stage('Clearing caches') {
615
steps {
716
script {
817
// Sleeps are since we don't watch for end of the process, and jobs only start the process
@@ -12,27 +21,64 @@ pipeline {
1221
[$class: 'BooleanParameterValue', name: 'RUN_ON_PROD', value: true]
1322
],
1423
wait: true)
15-
sleep(time:3,unit:"MINUTES")
24+
sleep(time:10,unit:"SECONDS")
1625

1726
build(job: 'angular.love/clear-site-cache', wait: true)
18-
sleep(time:30,unit:"SECONDS")
27+
sleep(time:1,unit:"MINUTES")
28+
}
29+
}
30+
}
31+
stage('Trigger Builds') {
32+
steps {
33+
script {
34+
build(job: 'angular.love/build-new-blog-main', wait: true)
35+
}
36+
}
37+
}
38+
stage('Wait for builds to finish') {
39+
steps {
40+
script {
41+
buildStatus = 'active'
42+
while (buildStatus == 'active') {
43+
sleep(time:1,unit:"MINUTES")
44+
withCredentials([
45+
usernamePassword(credentialsId: 'cf-workers-creds', usernameVariable: 'CLOUDFLARE_ACCOUNT_ID', passwordVariable: 'CLOUDFLARE_API_TOKEN'),
46+
]) {
47+
buildStatus = sh(script: """
48+
./scripts/get_last_build_status.sh -a $CLOUDFLARE_ACCOUNT_ID -p $PROJECT_NAME -t $CLOUDFLARE_API_TOKEN
49+
""", returnStdout: true).trim()
50+
}
51+
echo "Build status: ${buildStatus}"
52+
}
53+
1954

20-
build(job: 'angular.love/build-new-blog-main', wait: false)
21-
sleep(time:20,unit:"MINUTES")
55+
if (buildStatus != 'success') {
56+
error("Build failed")
57+
}
2258

59+
// Clear caches again to make sure they are cleared
2360
build(job: 'angular.love/clear-site-cache', wait: true)
61+
build(job: 'angular.love/clear-bff-cache',
62+
parameters: [
63+
[$class: 'BooleanParameterValue', name: 'RUN_ON_DEV', value: true],
64+
[$class: 'BooleanParameterValue', name: 'RUN_ON_PROD', value: true]
65+
],
66+
wait: true)
67+
68+
withCredentials([
69+
usernamePassword(credentialsId: 'cf-workers-creds', usernameVariable: 'CLOUDFLARE_ACCOUNT_ID', passwordVariable: 'CLOUDFLARE_API_TOKEN'),
70+
]) {
71+
buildUrl = sh(script: """
72+
./scripts/get_last_builds_url.sh -a $CLOUDFLARE_ACCOUNT_ID -p $PROJECT_NAME -t $CLOUDFLARE_API_TOKEN
73+
""", returnStdout: true).trim()
74+
}
75+
76+
echo "Build URL: ${buildUrl}"
77+
currentBuild.description = "Build URL: ${buildUrl}"
78+
currentBuild.displayName = "${buildUrl}"
2479
}
2580
}
2681
}
2782
}
28-
29-
post {
30-
failure {
31-
echo "Failed to trigger builds"
32-
}
33-
success {
34-
echo "Successfully triggered all builds"
35-
}
36-
}
3783
}
3884

Jenkinsfile.purge_kv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pipeline {
3434
usernamePassword(credentialsId: 'cf-workers-creds', usernameVariable: 'CLOUDFLARE_ACCOUNT_ID', passwordVariable: 'CLOUDFLARE_API_TOKEN'),
3535
]) {
3636
sh """
37-
./purge_kv.sh $KV_DEV
37+
./scripts/purge_kv.sh $KV_DEV
3838
"""
3939
}
4040
}
@@ -48,7 +48,7 @@ pipeline {
4848
usernamePassword(credentialsId: 'cf-workers-creds', usernameVariable: 'CLOUDFLARE_ACCOUNT_ID', passwordVariable: 'CLOUDFLARE_API_TOKEN'),
4949
]) {
5050
sh """
51-
./purge_kv.sh $KV_PROD
51+
./scripts/purge_kv.sh $KV_PROD
5252
"""
5353
}
5454
}

scripts/get_last_build_status.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
while getopts "a:p:t:" opt; do
4+
case $opt in
5+
a) ACCOUNT_ID="$OPTARG";;
6+
p) PROJECT_NAME="$OPTARG";;
7+
t) API_TOKEN="$OPTARG";;
8+
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
9+
esac
10+
done
11+
12+
if [ -z "$ACCOUNT_ID" ] || [ -z "$PROJECT_NAME" ] || [ -z "$API_TOKEN" ]; then
13+
echo "Usage: $0 -a ACCOUNT_ID -p PROJECT_NAME -t API_TOKEN"
14+
exit 1
15+
fi
16+
17+
get_latest_status() {
18+
response=$(curl -s -X GET \
19+
"https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/pages/projects/${PROJECT_NAME}/deployments" \
20+
-H "Authorization: Bearer ${API_TOKEN}" \
21+
-H "Content-Type: application/json")
22+
23+
if [ "$(echo "$response" | jq -r '.success')" != "true" ]; then
24+
echo "Error: $(echo "$response" | jq -r '.errors[0].message')"
25+
exit 1
26+
fi
27+
28+
echo "$response" | jq -r '.result[] | select(.environment == "production") | .latest_stage.status' | head -n1
29+
}
30+
31+
32+
if ! command -v jq &> /dev/null; then
33+
echo "Error: jq is required but not installed. Please install it first."
34+
exit 1
35+
fi
36+
37+
# Get and display status
38+
status=$(get_latest_status)
39+
echo "$status"

scripts/get_last_builds_url.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
while getopts "a:p:t:" opt; do
4+
case $opt in
5+
a) ACCOUNT_ID="$OPTARG";;
6+
p) PROJECT_NAME="$OPTARG";;
7+
t) API_TOKEN="$OPTARG";;
8+
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
9+
esac
10+
done
11+
12+
if [ -z "$ACCOUNT_ID" ] || [ -z "$PROJECT_NAME" ] || [ -z "$API_TOKEN" ]; then
13+
echo "Usage: $0 -a ACCOUNT_ID -p PROJECT_NAME -t API_TOKEN"
14+
exit 1
15+
fi
16+
17+
get_latest_status() {
18+
response=$(curl -s -X GET \
19+
"https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/pages/projects/${PROJECT_NAME}/deployments" \
20+
-H "Authorization: Bearer ${API_TOKEN}" \
21+
-H "Content-Type: application/json")
22+
23+
if [ "$(echo "$response" | jq -r '.success')" != "true" ]; then
24+
echo "Error: $(echo "$response" | jq -r '.errors[0].message')"
25+
exit 1
26+
fi
27+
28+
echo "$response" | jq -r '.result[] | select(.environment == "production") | .url' | head -n1
29+
}
30+
31+
32+
if ! command -v jq &> /dev/null; then
33+
echo "Error: jq is required but not installed. Please install it first."
34+
exit 1
35+
fi
36+
37+
# Get and display status
38+
status=$(get_latest_status)
39+
echo "$status"
File renamed without changes.

0 commit comments

Comments
 (0)