|
@@ -33,6 +33,7 @@ def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
def repos = repoNames.join(' ')
|
|
def repos = repoNames.join(' ')
|
|
|
|
|
+ // POSIX sh only (Jenkins sh step); no mapfile / process substitution
|
|
|
script.sh """
|
|
script.sh """
|
|
|
set -e
|
|
set -e
|
|
|
REG='${reg}'
|
|
REG='${reg}'
|
|
@@ -47,29 +48,36 @@ def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int
|
|
|
fi
|
|
fi
|
|
|
for repo in ${repos}; do
|
|
for repo in ${repos}; do
|
|
|
enc_repo=\$(printf '%s' "\${repo}" | jq -sRr @uri)
|
|
enc_repo=\$(printf '%s' "\${repo}" | jq -sRr @uri)
|
|
|
- mapfile -t tags < <(curl -fsS -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
|
|
|
|
|
|
+ tags_file=\$(mktemp)
|
|
|
|
|
+ curl -fsS -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
|
|
"http://\${REG}/api/v2.0/projects/\${PROJ}/repositories/\${enc_repo}/artifacts?page_size=100" \\
|
|
"http://\${REG}/api/v2.0/projects/\${PROJ}/repositories/\${enc_repo}/artifacts?page_size=100" \\
|
|
|
- | jq -r '.[] | .tags[]? | .name' | grep "^\${PREFIX}" | sort -t- -k3 -n || true)
|
|
|
|
|
- count=\${#tags[@]}
|
|
|
|
|
|
|
+ | jq -r '.[] | .tags[]? | .name' | grep "^\${PREFIX}" | sort -t- -k3 -n > "\${tags_file}" || true
|
|
|
|
|
+ count=\$(wc -l < "\${tags_file}" | tr -d ' ')
|
|
|
echo ">>> prune \${repo}: \${count} tag(s) matching \${PREFIX}*"
|
|
echo ">>> prune \${repo}: \${count} tag(s) matching \${PREFIX}*"
|
|
|
if [ "\${count}" -le "\${KEEP}" ]; then
|
|
if [ "\${count}" -le "\${KEEP}" ]; then
|
|
|
|
|
+ rm -f "\${tags_file}"
|
|
|
continue
|
|
continue
|
|
|
fi
|
|
fi
|
|
|
del_count=\$((count - KEEP))
|
|
del_count=\$((count - KEEP))
|
|
|
- i=0
|
|
|
|
|
- while [ "\${i}" -lt "\${del_count}" ]; do
|
|
|
|
|
- t="\${tags[\$i]}"
|
|
|
|
|
|
|
+ deleted=0
|
|
|
|
|
+ while IFS= read -r t; do
|
|
|
|
|
+ if [ -z "\${t}" ]; then
|
|
|
|
|
+ continue
|
|
|
|
|
+ fi
|
|
|
if [ "\${t}" = "\${CURRENT}" ] || [ "\${t}" = "\${LATEST}" ]; then
|
|
if [ "\${t}" = "\${CURRENT}" ] || [ "\${t}" = "\${LATEST}" ]; then
|
|
|
- i=\$((i + 1))
|
|
|
|
|
continue
|
|
continue
|
|
|
fi
|
|
fi
|
|
|
|
|
+ if [ "\${deleted}" -ge "\${del_count}" ]; then
|
|
|
|
|
+ break
|
|
|
|
|
+ fi
|
|
|
echo ">>> DELETE Harbor tag \${repo}:\${t}"
|
|
echo ">>> DELETE Harbor tag \${repo}:\${t}"
|
|
|
if ! curl -fsS -X DELETE -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
|
if ! curl -fsS -X DELETE -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
|
|
"http://\${REG}/api/v2.0/projects/\${PROJ}/repositories/\${enc_repo}/artifacts/\${t}/tags/\${t}"; then
|
|
"http://\${REG}/api/v2.0/projects/\${PROJ}/repositories/\${enc_repo}/artifacts/\${t}/tags/\${t}"; then
|
|
|
echo ">>> WARN: delete failed \${repo}:\${t} (check robot delete permission)"
|
|
echo ">>> WARN: delete failed \${repo}:\${t} (check robot delete permission)"
|
|
|
fi
|
|
fi
|
|
|
- i=\$((i + 1))
|
|
|
|
|
- done
|
|
|
|
|
|
|
+ deleted=\$((deleted + 1))
|
|
|
|
|
+ done < "\${tags_file}"
|
|
|
|
|
+ rm -f "\${tags_file}"
|
|
|
done
|
|
done
|
|
|
"""
|
|
"""
|
|
|
}
|
|
}
|
|
@@ -90,7 +98,7 @@ pipeline {
|
|
|
trim: true,
|
|
trim: true,
|
|
|
description: 'Git branch, must match remote (e.g. uat-20260202)'
|
|
description: 'Git branch, must match remote (e.g. uat-20260202)'
|
|
|
)
|
|
)
|
|
|
- booleanParam(name: 'FORCE_UPDATE', defaultValue: true, description: 'mvn -U')
|
|
|
|
|
|
|
+ booleanParam(name: 'FORCE_UPDATE', defaultValue: false, description: 'mvn -U (routine builds leave unchecked for speed)')
|
|
|
booleanParam(name: 'ALLOW_SNAPSHOTS', defaultValue: true, description: 'allow SNAPSHOT deps')
|
|
booleanParam(name: 'ALLOW_SNAPSHOTS', defaultValue: true, description: 'allow SNAPSHOT deps')
|
|
|
booleanParam(
|
|
booleanParam(
|
|
|
name: 'PUSH_TO_HARBOR',
|
|
name: 'PUSH_TO_HARBOR',
|
|
@@ -167,17 +175,24 @@ pipeline {
|
|
|
<id>repo-mix</id>
|
|
<id>repo-mix</id>
|
|
|
<repositories>
|
|
<repositories>
|
|
|
<repository>
|
|
<repository>
|
|
|
|
|
+ <id>aliyunmaven</id>
|
|
|
|
|
+ <name>Aliyun Maven</name>
|
|
|
|
|
+ <url>https://maven.aliyun.com/repository/public</url>
|
|
|
|
|
+ <releases><enabled>true</enabled><updatePolicy>daily</updatePolicy></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </repository>
|
|
|
|
|
+ <repository>
|
|
|
<id>central</id>
|
|
<id>central</id>
|
|
|
<name>Maven Central</name>
|
|
<name>Maven Central</name>
|
|
|
<url>https://repo.maven.apache.org/maven2</url>
|
|
<url>https://repo.maven.apache.org/maven2</url>
|
|
|
- <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
|
|
|
|
|
|
|
+ <releases><enabled>true</enabled><updatePolicy>daily</updatePolicy></releases>
|
|
|
<snapshots><enabled>false</enabled></snapshots>
|
|
<snapshots><enabled>false</enabled></snapshots>
|
|
|
</repository>
|
|
</repository>
|
|
|
<repository>
|
|
<repository>
|
|
|
<id>spring-milestones</id>
|
|
<id>spring-milestones</id>
|
|
|
<name>Spring Milestones</name>
|
|
<name>Spring Milestones</name>
|
|
|
<url>https://repo.spring.io/milestone</url>
|
|
<url>https://repo.spring.io/milestone</url>
|
|
|
- <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
|
|
|
|
|
|
|
+ <releases><enabled>true</enabled><updatePolicy>daily</updatePolicy></releases>
|
|
|
<snapshots><enabled>false</enabled></snapshots>
|
|
<snapshots><enabled>false</enabled></snapshots>
|
|
|
</repository>
|
|
</repository>
|
|
|
<repository>
|
|
<repository>
|
|
@@ -185,11 +200,17 @@ pipeline {
|
|
|
<name>Spring Snapshots</name>
|
|
<name>Spring Snapshots</name>
|
|
|
<url>https://repo.spring.io/snapshot</url>
|
|
<url>https://repo.spring.io/snapshot</url>
|
|
|
<releases><enabled>false</enabled></releases>
|
|
<releases><enabled>false</enabled></releases>
|
|
|
- <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
|
|
|
|
|
|
|
+ <snapshots><enabled>true</enabled><updatePolicy>daily</updatePolicy></snapshots>
|
|
|
</repository>
|
|
</repository>
|
|
|
</repositories>
|
|
</repositories>
|
|
|
<pluginRepositories>
|
|
<pluginRepositories>
|
|
|
<pluginRepository>
|
|
<pluginRepository>
|
|
|
|
|
+ <id>aliyunmaven</id>
|
|
|
|
|
+ <url>https://maven.aliyun.com/repository/public</url>
|
|
|
|
|
+ <releases><enabled>true</enabled></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </pluginRepository>
|
|
|
|
|
+ <pluginRepository>
|
|
|
<id>central</id>
|
|
<id>central</id>
|
|
|
<url>https://repo.maven.apache.org/maven2</url>
|
|
<url>https://repo.maven.apache.org/maven2</url>
|
|
|
<releases><enabled>true</enabled></releases>
|
|
<releases><enabled>true</enabled></releases>
|
|
@@ -223,11 +244,8 @@ pipeline {
|
|
|
mvn -version
|
|
mvn -version
|
|
|
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY all_proxy no_proxy NO_PROXY || true
|
|
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY all_proxy no_proxy NO_PROXY || true
|
|
|
export MAVEN_OPTS="-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true"
|
|
export MAVEN_OPTS="-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true"
|
|
|
- rm -rf /root/.m2/repository/org/springframework/cloud/spring-cloud-dependencies/Hoxton.SR1 || true
|
|
|
|
|
- rm -rf /root/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE || true
|
|
|
|
|
- rm -rf ${WORKSPACE}/.m2/repository/org/springframework/cloud/spring-cloud-dependencies/Hoxton.SR1 || true
|
|
|
|
|
- rm -rf ${WORKSPACE}/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE || true
|
|
|
|
|
- mvn clean package -DskipTests -s settings.xml ${updateFlag} -e -Dmaven.repo.local=${WORKSPACE}/.m2/repository
|
|
|
|
|
|
|
+ mkdir -p /var/jenkins_home/.m2/repository
|
|
|
|
|
+ mvn clean package -DskipTests -s settings.xml ${updateFlag} -e -Dmaven.repo.local=/var/jenkins_home/.m2/repository
|
|
|
"""
|
|
"""
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -308,10 +326,12 @@ pipeline {
|
|
|
}
|
|
}
|
|
|
if (params.HARBOR_PRUNE_OLD_TAGS == true) {
|
|
if (params.HARBOR_PRUNE_OLD_TAGS == true) {
|
|
|
def keepN = (params.HARBOR_KEEP_TAG_COUNT ?: '10').trim() as int
|
|
def keepN = (params.HARBOR_KEEP_TAG_COUNT ?: '10').trim() as int
|
|
|
- pruneHarborUatTags(
|
|
|
|
|
- this, reg, proj, harborServices*.repo,
|
|
|
|
|
- keepN, 'uat-build-', buildTag, latestTag,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
|
|
|
|
|
+ pruneHarborUatTags(
|
|
|
|
|
+ this, reg, proj, harborServices*.repo,
|
|
|
|
|
+ keepN, 'uat-build-', buildTag, latestTag,
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
echo ">>> Harbor latest: ${env.UAT_HARBOR_LATEST_TAG}; archived tag this run: ${env.UAT_HARBOR_BUILD_TAG}"
|
|
echo ">>> Harbor latest: ${env.UAT_HARBOR_LATEST_TAG}; archived tag this run: ${env.UAT_HARBOR_BUILD_TAG}"
|