Skip to content

Commit

Permalink
Refactor Jenkins pipeline to separate source preparation into its own…
Browse files Browse the repository at this point in the history
… function and streamline cloning process
  • Loading branch information
ptankov committed Feb 1, 2025
1 parent c89869a commit 588b147
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions cloud/jenkins/pso-gke.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ String getParam(String paramName, String keyName = null) {
}

void prepareNode() {
echo "=========================[ Cloning the sources ]========================="
git branch: 'master', url: 'https://github.com/Percona-Lab/jenkins-pipelines'
sh """
# sudo is needed for better node recovery after compilation failure
# if building failed on compilation stage directory will have files owned by docker user
sudo git config --global --add safe.directory '*'
sudo git reset --hard
sudo git clean -xdf
sudo rm -rf source
git clone -b $GIT_BRANCH https://github.com/percona/percona-server-mysql-operator source
"""

if ("$PILLAR_VERSION" != "none") {
echo "=========================[ Getting parameters for release test ]========================="
GKE_RELEASE_CHANNEL = "stable"
Expand Down Expand Up @@ -88,11 +76,25 @@ EOF
gcloud config set project $GCP_PROJECT
"""
}
}

void prepareSources() {
if ("$PLATFORM_VER" == "latest") {
PLATFORM_VER = sh(script: "gcloud container get-server-config --region=$region --flatten=channels --filter='channels.channel=RAPID' --format='value(channels.defaultVersion)' | cut -d- -f1", returnStdout: true).trim()
}

echo "=========================[ Cloning the sources ]========================="
git branch: 'master', url: 'https://github.com/Percona-Lab/jenkins-pipelines'
sh """
# sudo is needed for better node recovery after compilation failure
# if building failed on compilation stage directory will have files owned by docker user
sudo git config --global --add safe.directory '*'
sudo git reset --hard
sudo git clean -xdf
sudo rm -rf source
git clone -b $GIT_BRANCH https://github.com/percona/percona-server-mysql-operator source
"""

if ("$IMAGE_MYSQL") {
cw = ("$CLUSTER_WIDE" == "YES") ? "CW" : "NON-CW"
currentBuild.displayName = "#" + currentBuild.number + " $GIT_BRANCH"
Expand Down Expand Up @@ -174,6 +176,7 @@ void initTests() {
cp $CLOUD_SECRET_FILE source/e2e-tests/conf/cloud-secret.yml
"""
}
stash includes: "source/**", name: "sourceFILES"
}

void clusterRunner(String cluster) {
Expand Down Expand Up @@ -391,6 +394,7 @@ pipeline {
stage('Prepare Node') {
steps {
prepareNode()
prepareSources()
}
}
stage('Docker Build and Push') {
Expand All @@ -404,29 +408,57 @@ pipeline {
}
}
stage('Run Tests') {
options {
timeout(time: 3, unit: 'HOURS')
}
parallel {
stage('cluster1') {
agent {
label 'docker'
}
steps {
prepareNode()
unstash "sourceFILES"
clusterRunner('cluster1')
}
}
stage('cluster2') {
agent {
label 'docker'
}
steps {
prepareNode()
unstash "sourceFILES"
clusterRunner('cluster2')
}
}
stage('cluster3') {
agent {
label 'docker'
}
steps {
prepareNode()
unstash "sourceFILES"
clusterRunner('cluster3')
}
}
stage('cluster4') {
agent {
label 'docker'
}
steps {
prepareNode()
unstash "sourceFILES"
clusterRunner('cluster4')
}
}
stage('cluster5') {
agent {
label 'docker'
}
steps {
prepareNode()
unstash "sourceFILES"
clusterRunner('cluster5')
}
}
Expand Down

0 comments on commit 588b147

Please sign in to comment.