Skip to content

Commit 9f69146

Browse files
feat: add build number to clean db (#438)
* feat: add build number to clean db * fix: make hash smaller
1 parent d2bcef1 commit 9f69146

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Jenkinsfile.deploy

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ pipeline {
8585
def random = Math.abs(new Random().nextInt())
8686
env.BRANCH_HASH = "${random}"
8787

88-
if (env.BRANCH_HASH.length() > 10) {
89-
env.BRANCH_HASH = env.BRANCH_HASH.substring(0, 10)
88+
if (env.BRANCH_HASH.length() > 5) {
89+
env.BRANCH_HASH = env.BRANCH_HASH.substring(0, 5)
9090
}
9191

9292
def branchNameForDB = env.USE_BRANCH_NAME
@@ -98,20 +98,20 @@ pipeline {
9898
branchNameForDB = branchNameForDB.replace("/", "-")
9999
branchNameForDB = branchNameForDB.toLowerCase()
100100

101-
env.DB_BRANCH_NAME = "${ENVIRONMENT}-${branchNameForDB}-${BRANCH_HASH}"
102-
if (env.DB_BRANCH_NAME.length() > 50) {
103-
error("DB branch name is too long, truncating to 50 characters")
101+
env.DB_BRANCH_NAME = "${ENVIRONMENT}-${branchNameForDB}-${BUILD_NUMBER}-${BRANCH_HASH}"
102+
if (env.DB_BRANCH_NAME.length() > 46) { // 46 since we will be adding the group name to the db name
103+
error("DB branch name is too long")
104104
}
105-
withCredentials([string(credentialsId: 'tursor_api_token', variable: 'TURSO_API_TOKEN')]) {
105+
withCredentials([string(credentialsId: 'tursor_api_token', variable: 'TURSO_API_TOKEN')]) {
106106
sh """
107107
turso org switch angular-love
108108
turso db create eu-${DB_BRANCH_NAME} --from-db $TURSO_EU_DB --group blog-eu
109109
turso db create usw-${DB_BRANCH_NAME} --from-db $TURSO_US_WEST_DB --group blog-us-west
110110
turso db create use-${DB_BRANCH_NAME} --from-db $TURSO_US_EAST_DB --group blog-us-east
111111

112-
turso db list | grep -q "eu-${DB_BRANCH_NAME}" || { echo "EU database not found after creation"; exit 1; }
113-
turso db list | grep -q "usw-${DB_BRANCH_NAME}" || { echo "US West database not found after creation"; exit 1; }
114-
turso db list | grep -q "use-${DB_BRANCH_NAME}" || { echo "US East database not found after creation"; exit 1; }
112+
turso db list -g blog-eu | grep -q "eu-${DB_BRANCH_NAME}" || { echo "EU database not found after creation"; exit 1; }
113+
turso db list -g blog-us-west | grep -q "usw-${DB_BRANCH_NAME}" || { echo "US West database not found after creation"; exit 1; }
114+
turso db list -g blog-us-east | grep -q "use-${DB_BRANCH_NAME}" || { echo "US East database not found after creation"; exit 1; }
115115
"""
116116
env.TURSO_EU_CONNECTION_URL = "libsql://eu-${DB_BRANCH_NAME}-angular-love.turso.io"
117117
env.TURSO_US_WEST_CONNECTION_URL = "libsql://usw-${DB_BRANCH_NAME}-angular-love.turso.io"
@@ -123,6 +123,7 @@ pipeline {
123123
[$class: 'StringParameterValue', name: 'env', value: "${ENVIRONMENT}"],
124124
[$class: 'StringParameterValue', name: 'branchName', value: "${branchNameForDB}"],
125125
[$class: 'StringParameterValue', name: 'branchHash', value: "${BRANCH_HASH}"],
126+
[$class: 'StringParameterValue', name: 'buildNumber', value: "${BUILD_NUMBER}"],
126127
[$class: 'BooleanParameterValue', name: 'dryRun', value: false]], wait: false)
127128

128129
}

0 commit comments

Comments
 (0)