#!/bin/bash -ex
# This file writes variables to a .env file, to be copied to the runner and nodes.
# It goes in the home directory of the root user for now

# Start with a clear slate
rm -f .env || :

# The Jenkins build number
echo JENKINS_BUILD_NUMBER=${BUILD_NUMBER} >> .env

# The Jenkins job name
echo JENKINS_JOB_NAME=${JOB_NAME} >> .env

# The Jenkins workspace
echo JENKINS_WORKSPACE=${WORKSPACE} >> .env

# The Jenkins build tag
echo JENKINS_BUILD_TAG=${BUILD_TAG} >> .env

# The group name for the launched vms
GROUP=${JOB_NAME}-${BUILD_NUMBER}
echo IW_VM_GROUP_NAME=${GROUP} >> .env

# The committish under test
echo IW_COMMITTISH=${GERRIT_REFSPEC} >> .env

# Folder defining the testrun.d suite
echo IW_TESTRUN_DIR=${IW_TESTRUN_DIR} >> .env

# Indicate if we're running locally, instead of via Jenkins
if [ ${IW_IS_LOCAL_TEST} ]; then
  echo IW_IS_LOCAL_TEST=1 >> .env
else
  echo IW_IS_LOCAL_TEST=0 >> .env
fi

# User who started the build process
echo JENKINS_CHANGE_AUTHOR="${GERRIT_CHANGE_OWNER_EMAIL%@*}" >> .env