Skip to content

Commit

Permalink
Add token credential check before calling orchestrator logic
Browse files Browse the repository at this point in the history
Signed-off-by: manasvinibs <[email protected]>
  • Loading branch information
manasvinibs committed Feb 5, 2024
1 parent 94a5d3c commit ef29a09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
20 changes: 20 additions & 0 deletions auth.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
// Fetch GitHub credentials using Jenkins' withCredentials step
def getCredentials() {
try {
withCredentials([usernamePassword(credentialsId: 'jenkins-github-bot-token', passwordVariable: 'GITHUB_TOKEN', usernameVariable: 'GITHUB_USER')]) {
env.REMOTE_GITHUB_TOKEN = sh(script: 'echo $GITHUB_TOKEN', returnStdout: true).trim()
}
} catch (Exception ex) {
echo "Error: Unable to fetch GitHub token from Jenkins credentials. Message: ${ex.getMessage()}"
}
}

getCredentials()
11 changes: 10 additions & 1 deletion integtest.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ echo -e "Test Files List:"
echo $TEST_FILES | tr ',' '\n'
echo "BROWSER_PATH: $BROWSER_PATH"

# Verify if GITHUB_TOKEN is empty and if yes call groovy function to get the credentials as part of Jenkins pipeline step
if [ -z "$GITHUB_TOKEN" ]; then
# integtest script is run as part of release CI jenkins job where groovy is installed
groovy auth.groovy
export GITHUB_TOKEN="$REMOTE_GITHUB_TOKEN"
else
echo "GITHUB_TOKEN is not empty. Skipping credential retrieval."
fi

# Can be used as Jenkins environment variable set for the orchestrator feature flag, default: true
ORCHESTRATOR_FEATURE_FLAG=${ORCHESTRATOR_FEATURE_FLAG:-true}

Expand Down Expand Up @@ -167,7 +176,7 @@ wait_file() {
done < "$pid_file"
}

if [[ $REMOTE_CYPRESS_ENABLED = "true" && $ORCHESTRATOR_FEATURE_FLAG = 'true' ]]; then
if [[ -n "$GITHUB_TOKEN" && $REMOTE_CYPRESS_ENABLED && $ORCHESTRATOR_FEATURE_FLAG ]]; then
# Parse the JSON file to iterate over the components array
components=$(jq -c '.components[]' "$REMOTE_MANIFEST_FILE")
echo "Components: $components"
Expand Down

0 comments on commit ef29a09

Please sign in to comment.