Skip to content

Commit b1abc71

Browse files
committed
Fix withEnv inside the script to be used from the stage commit and push changes
1 parent 7a88a8e commit b1abc71

1 file changed

Lines changed: 29 additions & 36 deletions

File tree

testrail/Jenkinsfile.check-bitrise-ios-release-tags

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,50 +69,43 @@ pipeline {
6969
environment {
7070
PATH = "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
7171
}
72-
when {
73-
expression {
74-
// Only run if latest_tags.json was modified by the script
72+
steps {
73+
script {
7574
def changed = sh(script: 'git diff --quiet testrail/latest_tags.json', returnStatus: true)
7675
if (changed != 0) {
7776
echo "✅ New version detected - latest_tags.json was modified"
78-
return true
79-
} else {
80-
echo "ℹ️ No new versions detected - skipping commit and push"
81-
return false
82-
}
83-
}
84-
}
85-
steps {
86-
script {
87-
sh '''
88-
set -e
89-
git config --global user.name 'jenkins-automation'
90-
git config --global user.email 'jenkins@automation.local'
91-
git add testrail/latest_tags.json
92-
'''
93-
withCredentials([usernamePassword(credentialsId: 'github-token',
94-
usernameVariable: 'GIT_USERNAME',
95-
passwordVariable: 'GIT_TOKEN')]) {
9677
sh '''
9778
set -e
98-
git commit -m 'Automated update of latest_tags'
99-
# Configure git to use token via credential helper (avoids URL encoding issues)
100-
git config --local credential.helper '!f() {
101-
while IFS= read -r line; do
102-
test -z "$line" && break
103-
done
104-
echo "username=${GIT_USERNAME}"
105-
echo "password=${GIT_TOKEN}"
106-
}; f'
79+
git config --global user.name 'jenkins-automation'
80+
git config --global user.email 'jenkins@automation.local'
81+
git add testrail/latest_tags.json
82+
'''
83+
withCredentials([usernamePassword(credentialsId: 'github-token',
84+
usernameVariable: 'GIT_USERNAME',
85+
passwordVariable: 'GIT_TOKEN')]) {
86+
sh '''
87+
set -e
88+
git commit -m 'Automated update of latest_tags'
89+
# Configure git to use token via credential helper (avoids URL encoding issues)
90+
git config --local credential.helper '!f() {
91+
while IFS= read -r line; do
92+
test -z "$line" && break
93+
done
94+
echo "username=${GIT_USERNAME}"
95+
echo "password=${GIT_TOKEN}"
96+
}; f'
10797

108-
# Get the repository URL from remote origin (no hardcoding)
109-
REPO_URL=$(git config --get remote.origin.url)
98+
# Get the repository URL from remote origin (no hardcoding)
99+
REPO_URL=$(git config --get remote.origin.url)
110100

111-
# Push to main branch (Jenkins runs in detached HEAD state)
112-
git push "$REPO_URL" HEAD:refs/heads/main
113-
'''
101+
# Push to main branch (Jenkins runs in detached HEAD state)
102+
git push "$REPO_URL" HEAD:refs/heads/main
103+
'''
104+
}
105+
echo 'Changes committed and pushed successfully'
106+
} else {
107+
echo "ℹ️ No new versions detected - skipping commit and push"
114108
}
115-
echo 'Changes committed and pushed successfully'
116109
}
117110
}
118111
}

0 commit comments

Comments
 (0)