@@ -85,8 +85,8 @@ pipeline {
85
85
def random = Math.abs(new Random().nextInt())
86
86
env.BRANCH_HASH = "${random}"
87
87
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 )
90
90
}
91
91
92
92
def branchNameForDB = env.USE_BRANCH_NAME
@@ -98,20 +98,20 @@ pipeline {
98
98
branchNameForDB = branchNameForDB.replace("/", "-")
99
99
branchNameForDB = branchNameForDB.toLowerCase()
100
100
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")
104
104
}
105
- withCredentials([string(credentialsId: 'tursor_api_token', variable: 'TURSO_API_TOKEN')]) {
105
+ withCredentials([string(credentialsId: 'tursor_api_token', variable: 'TURSO_API_TOKEN')]) {
106
106
sh """
107
107
turso org switch angular-love
108
108
turso db create eu-${DB_BRANCH_NAME} --from-db $TURSO_EU_DB --group blog-eu
109
109
turso db create usw-${DB_BRANCH_NAME} --from-db $TURSO_US_WEST_DB --group blog-us-west
110
110
turso db create use-${DB_BRANCH_NAME} --from-db $TURSO_US_EAST_DB --group blog-us-east
111
111
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; }
115
115
"""
116
116
env.TURSO_EU_CONNECTION_URL = "libsql://eu-${DB_BRANCH_NAME}-angular-love.turso.io"
117
117
env.TURSO_US_WEST_CONNECTION_URL = "libsql://usw-${DB_BRANCH_NAME}-angular-love.turso.io"
@@ -123,6 +123,7 @@ pipeline {
123
123
[$class: 'StringParameterValue', name: 'env', value: "${ENVIRONMENT}"],
124
124
[$class: 'StringParameterValue', name: 'branchName', value: "${branchNameForDB}"],
125
125
[$class: 'StringParameterValue', name: 'branchHash', value: "${BRANCH_HASH}"],
126
+ [$class: 'StringParameterValue', name: 'buildNumber', value: "${BUILD_NUMBER}"],
126
127
[$class: 'BooleanParameterValue', name: 'dryRun', value: false]], wait: false)
127
128
128
129
}
0 commit comments