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

Add dev tool for finding Jenkins jobs for a Beats PR #15912

Merged
merged 3 commits into from
Jan 28, 2020
Merged
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions dev-tools/find_pr_jenkins_jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Description:
# This script finds Jenkins jobs for a given Beats PR.
#
# Usage:
# ./find_pr_jenkins_job.sh PR_NUMBER
#
# Example:
# ./find_pr_jenkins_job.sh 15790
#

set -e

NUM_JOBS_TO_SEARCH=100

get_pr_from_input() {
pr=$1
if [ -z $pr ]; then
echo "Usage: ./find_jenkins_job.sh PR_NUMBER" >&2
exit 1
fi

echo $pr
}

find_latest_beats_pr_job() {
curl -s 'https://beats-ci.elastic.co/job/elastic+beats+pull-request/api/json' | jq '.builds[0].number'
}

find_job_for_pr() {
job=$1
pr=$2

found=$(curl -s "https://beats-ci.elastic.co/job/elastic+beats+pull-request/$job/api/json" \
| jq -c ".actions[] | select(._class == \"org.jenkinsci.plugins.ghprb.GhprbParametersAction\").parameters[] | select(.name == \"ghprbPullId\" and .value == \"$pr\")" \
| wc -l)

echo $found
}

main() {
pr=$(get_pr_from_input $1)
echo "Searching last $NUM_JOBS_TO_SEARCH Jenkins jobs for PR number: $pr..."

n=$(find_latest_beats_pr_job $pr)
let e=$n-$NUM_JOBS_TO_SEARCH

while [ $n -gt $e ]; do
found=$(find_job_for_pr $n $pr)
if [ $found -gt 0 ]; then
echo "https://beats-ci.elastic.co/job/elastic+beats+pull-request/$n/"
fi

let n=$n-1
done
}

main $1