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

sending branch name to webhooks/integrations/ci-cd #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion trigger_pentest.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@

URL=https://api.getastra.com/webhooks/integrations/ci-cd
ASTRA_SCAN_TYPE="${ASTRA_SCAN_TYPE:-lightning}"
status_code=$(curl -s -o response.txt -w "%{http_code}" --user-agent "Astra Pentest Trigger Script/1.0" --header "Content-Type: application/json" --request POST --data "{\"accessToken\":\"$ASTRA_ACCESS_TOKEN\",\"projectId\":\"$ASTRA_PROJECT_ID\", \"mode\":\"$ASTRA_AUDIT_MODE\", \"automatedScanType\":\"$ASTRA_SCAN_TYPE\"}" $URL)

if [ -n "$ASTRA_CI_BRANCH_NAME" ]; then # OTHER CI
BRANCH_NAME="$ASTRA_CI_BRANCH_NAME"
else
if [ -n "$GITHUB_ACTIONS" ]; then # GITHUB
BRANCH_NAME="${GITHUB_REF}"
elif [ -n "$GITLAB_CI" ]; then # GITLAB
BRANCH_NAME="$CI_COMMIT_REF_NAME"
elif [ -n "$CIRCLECI" ]; then # CIRCLECI
BRANCH_NAME="$CIRCLE_BRANCH"
elif [ -n "$BITBUCKET_PIPELINE_UUID" ]; then # BITBUCKET
if [ -n "$BITBUCKET_BRANCH" ]; then
BRANCH_NAME="$BITBUCKET_BRANCH"
elif [ -n "$BITBUCKET_TAG" ]; then
BRANCH_NAME="$BITBUCKET_TAG"
else
echo "⛔ Bitbucket: The branch name for the custom pipeline is not recognized."
exit 1
fi
elif [ -n "${JENKINS_URL}" ]; then # JENKINS
BRANCH_NAME="${BRANCH_NAME}"
elif [ -n "$SYSTEM_TEAMFOUNDATIONCOLLECTIONURI" ]; then # AZURE
BRANCH_NAME="${BUILD_SOURCEBRANCH}"
else
echo "⛔ The branch name retrieval is unsuccessful as the CI/CD platform cannot be determined."
exit 1
fi
fi

status_code=$(curl -s -o response.txt -w "%{http_code}" --user-agent "Astra Pentest Trigger Script/1.0" --header "Content-Type: application/json" --request POST --data "{\"accessToken\":\"$ASTRA_ACCESS_TOKEN\",\"projectId\":\"$ASTRA_PROJECT_ID\", \"mode\":\"$ASTRA_AUDIT_MODE\", \"automatedScanType\":\"$ASTRA_SCAN_TYPE\", \"branchName\":\"$BRANCH_NAME\"}" $URL)
if [[ "$status_code" == "200" ]] ; then
echo "✅ Astra pentest was successfully started."
cat response.txt
Expand Down