Last active
November 21, 2022 12:57
-
-
Save subudear/53edd93e5dc9ed51a843a48ea9fa4cbe to your computer and use it in GitHub Desktop.
install vsts build agent on ubuntu (requires env.sh as well)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
. env.sh | |
#export VSO_AGENT_IGNORE=_,MAIL,OLDPWD,PATH,PWD,VSTS_AGENT,VSTS_ACCOUNT,VSTS_TOKEN_FILE,VSTS_TOKEN,VSTS_POOL,VSTS_WORK,VSO_AGENT_IGNORE | |
if [ ! -e $VSTS_HOME/.configure ]; then | |
touch $VSTS_HOME/.configure | |
fi | |
if [ ! -e $VSTS_HOME/.token ]; then | |
touch $VSTS_HOME/.token | |
fi | |
if [ $(dpkg-query -W -f='${Status}' jq 2>/dev/null | grep -c "ok installed") -eq 0 ]; then | |
sudo apt-get install jq | |
fi | |
if [ -n "$VSTS_AGENT_IGNORE" ]; then | |
export VSO_AGENT_IGNORE=$VSO_AGENT_IGNORE,VSTS_AGENT_IGNORE,$VSTS_AGENT_IGNORE | |
fi | |
if [ -e $VSTS_HOME/agent -a ! -e $VSTS_HOME/.configure ]; then | |
trap 'kill -SIGINT $!; exit 130' INT | |
trap 'kill -SIGTERM $!; exit 143' TERM | |
$VSTS_HOME/agent/bin/Agent.Listener run & wait $! | |
exit $? | |
fi | |
if [ -z "$VSTS_ACCOUNT" ]; then | |
echo 1>&2 error: missing VSTS_ACCOUNT environment variable | |
exit 1 | |
fi | |
if [ -z "$VSTS_TOKEN_FILE" ]; then | |
if [ -z "$VSTS_TOKEN" ]; then | |
echo 1>&2 error: missing VSTS_TOKEN environment variable | |
exit 1 | |
fi | |
VSTS_TOKEN_FILE=$VSTS_HOME/.token | |
echo -n $VSTS_TOKEN > "$VSTS_TOKEN_FILE" | |
fi | |
unset VSTS_TOKEN | |
if [ -n "$VSTS_AGENT" ]; then | |
export VSTS_AGENT="$(eval echo $VSTS_AGENT)" | |
fi | |
if [ -n "$VSTS_WORK" ]; then | |
export VSTS_WORK="$(eval echo $VSTS_WORK)" | |
mkdir -p "$VSTS_WORK" | |
fi | |
#touch /vsts/.configure | |
rm -rf $VSTS_HOME/agent | |
mkdir $VSTS_HOME/agent | |
cd $VSTS_HOME/agent | |
cleanup() { | |
if [ -e config.sh ]; then | |
./bin/Agent.Listener remove --unattended \ | |
--auth PAT \ | |
--token $(cat "$VSTS_TOKEN_FILE") | |
fi | |
} | |
trap 'cleanup; exit 130' INT | |
trap 'cleanup; exit 143' TERM | |
echo Determining matching VSTS agent... | |
VSTS_AGENT_RESPONSE=$(curl -LsS \ | |
-u user:$(cat "$VSTS_TOKEN_FILE") \ | |
-H 'Accept:application/json;api-version=3.0-preview' \ | |
"https://$VSTS_ACCOUNT.visualstudio.com/_apis/distributedtask/packages/agent?platform=linux-x64") | |
if echo "$VSTS_AGENT_RESPONSE" | jq . >/dev/null 2>&1; then | |
VSTS_AGENT_URL=$(echo "$VSTS_AGENT_RESPONSE" \ | |
| jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]') | |
fi | |
if [ -z "$VSTS_AGENT_URL" -o "$VSTS_AGENT_URL" == "null" ]; then | |
echo 1>&2 error: could not determine a matching VSTS agent - check that account \'$VSTS_ACCOUNT\' is correct and the token is valid for that account | |
exit 1 | |
fi | |
echo Downloading and installing VSTS agent... | |
curl -LsS $VSTS_AGENT_URL | tar -xz --no-same-owner & wait $! | |
#source ./env.sh | |
./bin/Agent.Listener configure --unattended \ | |
--agent "${VSTS_AGENT:-$(hostname)}" \ | |
--url "https://$VSTS_ACCOUNT.visualstudio.com" \ | |
--auth PAT \ | |
--token $(cat "$VSTS_TOKEN_FILE") \ | |
--pool "${VSTS_POOL:-Default}" \ | |
--work "${VSTS_WORK:-_work}" \ | |
--replace & wait $! | |
./bin/Agent.Listener run & wait $! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download the env.sh from <script src="https://gist.github.com/subudear/f506d32856cb96e31dfc03d4121cf8a5.js"></script>