Skip to content

Webhook Issue with Environment user variables

Initial state

Hook definition:

- command-working-directory: /opt/main/
  execute-command: /opt/main/main.sh
  id: main
  pass-arguments-to-command:
  - {name: project, source: payload}

In script /opt/main/main.sh

env > /tmp/webhook-env.log

Result

# cat /tmp/webhook-env.log 
PWD=/opt/main
SYSTEMD_EXEC_PID=463
LANG=C.UTF-8
INVOCATION_ID=1397aa8628ac44558914776966d97572
SHLVL=1
JOURNAL_STREAM=8:16626
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env

Issue

There are no variables HOME, USER. Git can not clone/pull repositories with save authorization from github.

Solution

Case 1: Add variables in script

export HOME=/root
export USER=root

Case 2: Use .env file

# cat .env
HOME=/root
USER=root

# in script
set -a
source .env