Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opensearch gradle check migration to public jenkins (Old) #3698

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/gradle-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Jenkins Gradle Check
on: [pull_request]
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved

jobs:
gradle_check:
runs-on: ubuntu-latest
timeout-minutes: 130
Copy link
Member

@owaiskazi19 owaiskazi19 Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we deciding the timeout here to be 130? Did we document it somewhere?

steps:
- name: Setup environment variables
run: |
echo "pr_from_sha=$(jq --raw-output .pull_request.head.sha $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
echo "pr_from_clone_url=$(jq --raw-output .pull_request.head.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
echo "pr_to_clone_url=$(jq --raw-output .pull_request.base.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
echo "pr_title=$(jq --raw-output .pull_request.title $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV

- name: Trigger jenkins workflow to run gradle check
run: |
#!/bin/bash
echo "${{ env.pr_to_clone_url }} PR: ${{ env.pr_number }}"
echo "Raise from ${{ env.pr_from_clone_url }} ${{ env.pr_from_sha }}"
echo "PR Title: ${{ env.pr_title }}"
JENKINS_URL="https://build.ci.opensearch.org"
WORKFLOW_NAME="gradle_check"
TIMEPASS=0
TIMEOUT=7200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

RESULT="null"

echo "Trigger Jenkins workflows"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a Jenkins CLI to do this and avoid having to hand roll the entire request/wait/response flow?

java -jar jenkins-cli.jar ...

Copy link
Member

@dblock dblock Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JENKINS_REQ=$(curl -s -XPOST \
-H "Authorization: Bearer ${{ secrets.JENKINS_GRADLE_CHECK_GENERIC_WEBHOOK_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"pr_from_sha": "${{ env.pr_from_sha }}", "pr_from_clone_url": "${{ env.pr_from_clone_url }}", "pr_to_clone_url": "${{ env.pr_to_clone_url }}", "pr_title": "${{ env.pr_title }}", "pr_number": "${{ env.pr_number }}"}' \
'https://build.ci.opensearch.org/generic-webhook-trigger/invoke')

QUEUE_URL=$(echo $JENKINS_REQ | jq --raw-output .jobs.gradle_check.url)
echo QUEUE_URL $QUEUE_URL
echo "wait for jenkins to start workflow" && sleep 15

echo "Check if queue exist in Jenkins after triggering"
if [ -z "$QUEUE_URL" ] || [ "$QUEUE_URL" != "null" ]; then
WORKFLOW_URL=$(curl -s -XGET ${JENKINS_URL}/${QUEUE_URL}api/json | jq --raw-output .executable.url)
echo WORKFLOW_URL $WORKFLOW_URL

echo "Use queue information to find build number in Jenkins if available"
if [ -z "$WORKFLOW_URL" ] || [ "$WORKFLOW_URL" != "null" ]; then

RUNNING="true"

echo "Waiting for Jenkins to complete the run"
while [ "$RUNNING" = "true" ] && [ "$TIMEPASS" -le "$TIMEOUT" ]; do
echo "Still running, wait for another 30 seconds before checking again, max timeout $TIMEOUT"
echo "Jenkins Workflow Url: $WORKFLOW_URL"
TIMEPASS=$(( TIMEPASS + 30 )) && echo time pass: $TIMEPASS
sleep 30
RUNNING=$(curl -s -XGET ${WORKFLOW_URL}api/json | jq --raw-output .building)
done

echo "Complete the run, checking results now......"
RESULT=$(curl -s -XGET ${WORKFLOW_URL}api/json | jq --raw-output .result)

fi
fi

echo "Please check jenkins url for logs: $WORKFLOW_URL"

if [ "$RESULT" != "SUCCESS" ]; then
echo "Result: $RESULT"
exit 1
else
echo "Result: $RESULT"
echo 0
fi
32 changes: 0 additions & 32 deletions jenkins/jenkinsfile

This file was deleted.