-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-notifier.sh
67 lines (58 loc) · 4.11 KB
/
build-notifier.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
set -e
# Change dir to build notifier
cd $HOME/bitbucket-pipeline-step-notifier
# Install nodejs
installNodejs() {
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install 14
nvm install-latest-npm
}
# Install nodejs if not found
if ! which node > /dev/null; then
echo "Installing nodejs"
installNodejs
fi
# Upgrade nodejs if major version < 14
NODE_MAJOR_VERSION=$(node --version | sed 's/v//g' | sed 's/\..*$//g')
if [ $NODE_MAJOR_VERSION -lt '14' ]; then
echo "Upgrading nodejs"
installNodejs
fi
# Install jq
apt-get update && apt-get install -y jq
# Install build notifier dependencies
npm i
# Write pipeline vars
PIPE_VARS=$( jq -n \
--arg CI "$CI" \
--arg BITBUCKET_BUILD_NUMBER "$BITBUCKET_BUILD_NUMBER" \
--arg BITBUCKET_CLONE_DIR "$BITBUCKET_CLONE_DIR" \
--arg BITBUCKET_COMMIT "$BITBUCKET_COMMIT" \
--arg BITBUCKET_WORKSPACE "$BITBUCKET_WORKSPACE" \
--arg BITBUCKET_REPO_SLUG "$BITBUCKET_REPO_SLUG" \
--arg BITBUCKET_REPO_UUID "$BITBUCKET_REPO_UUID" \
--arg BITBUCKET_REPO_FULL_NAME "$BITBUCKET_REPO_FULL_NAME" \
--arg BITBUCKET_BRANCH "$BITBUCKET_BRANCH" \
--arg BITBUCKET_TAG "$BITBUCKET_TAG" \
--arg BITBUCKET_BOOKMARK "$BITBUCKET_BOOKMARK" \
--arg BITBUCKET_PARALLEL_STEP "$BITBUCKET_PARALLEL_STEP" \
--arg BITBUCKET_PARALLEL_STEP_COUNT "$BITBUCKET_PARALLEL_STEP_COUNT" \
--arg BITBUCKET_PR_ID "$BITBUCKET_PR_ID" \
--arg BITBUCKET_PR_DESTINATION_BRANCH "$BITBUCKET_PR_DESTINATION_BRANCH" \
--arg BITBUCKET_GIT_HTTP_ORIGIN "$BITBUCKET_GIT_HTTP_ORIGIN" \
--arg BITBUCKET_GIT_SSH_ORIGIN "$BITBUCKET_GIT_SSH_ORIGIN" \
--arg BITBUCKET_EXIT_CODE "$BITBUCKET_EXIT_CODE" \
--arg BITBUCKET_STEP_UUID "$BITBUCKET_STEP_UUID" \
--arg BITBUCKET_PIPELINE_UUID "$BITBUCKET_PIPELINE_UUID" \
--arg BITBUCKET_DEPLOYMENT_ENVIRONMENT "$BITBUCKET_DEPLOYMENT_ENVIRONMENT" \
--arg BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID "$BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID" \
--arg BITBUCKET_PROJECT_KEY "$BITBUCKET_PROJECT_KEY" \
--arg BITBUCKET_PROJECT_UUID "$BITBUCKET_PROJECT_UUID" \
--arg BITBUCKET_STEP_TRIGGERER_UUID "$BITBUCKET_STEP_TRIGGERER_UUID" \
--arg BITBUCKET_STEP_OIDC_TOKEN "$BITBUCKET_STEP_OIDC_TOKEN" \
'{CI: $CI, BITBUCKET_BUILD_NUMBER: $BITBUCKET_BUILD_NUMBER, BITBUCKET_CLONE_DIR: $BITBUCKET_CLONE_DIR, BITBUCKET_COMMIT: $BITBUCKET_COMMIT, BITBUCKET_WORKSPACE: $BITBUCKET_WORKSPACE, BITBUCKET_REPO_SLUG: $BITBUCKET_REPO_SLUG, BITBUCKET_REPO_UUID: $BITBUCKET_REPO_UUID, BITBUCKET_REPO_FULL_NAME: $BITBUCKET_REPO_FULL_NAME, BITBUCKET_BRANCH: $BITBUCKET_BRANCH, BITBUCKET_TAG: $BITBUCKET_TAG, BITBUCKET_BOOKMARK: $BITBUCKET_BOOKMARK, BITBUCKET_PARALLEL_STEP: $BITBUCKET_PARALLEL_STEP, BITBUCKET_PARALLEL_STEP_COUNT: $BITBUCKET_PARALLEL_STEP_COUNT, BITBUCKET_PR_ID: $BITBUCKET_PR_ID, BITBUCKET_PR_DESTINATION_BRANCH: $BITBUCKET_PR_DESTINATION_BRANCH, BITBUCKET_GIT_HTTP_ORIGIN: $BITBUCKET_GIT_HTTP_ORIGIN, BITBUCKET_GIT_SSH_ORIGIN: $BITBUCKET_GIT_SSH_ORIGIN, BITBUCKET_EXIT_CODE: $BITBUCKET_EXIT_CODE, BITBUCKET_STEP_UUID: $BITBUCKET_STEP_UUID, BITBUCKET_PIPELINE_UUID: $BITBUCKET_PIPELINE_UUID, BITBUCKET_DEPLOYMENT_ENVIRONMENT: $BITBUCKET_DEPLOYMENT_ENVIRONMENT, BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID: $BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID, BITBUCKET_PROJECT_KEY: $BITBUCKET_PROJECT_KEY, BITBUCKET_PROJECT_UUID: $BITBUCKET_PROJECT_UUID, BITBUCKET_STEP_TRIGGERER_UUID: $BITBUCKET_STEP_TRIGGERER_UUID, BITBUCKET_STEP_OIDC_TOKEN: $BITBUCKET_STEP_OIDC_TOKEN}' )
echo $PIPE_VARS > ./.pipe-vars.json
# Run nodejs build notifier
node build-notifier.js $NOTIFIER_WEBHOOK $1