2018-05-18 15:49:32 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# This script creates a project, a jobset with an input of type local
|
|
|
|
# path. This local path is a directory that contains a Nix expression
|
|
|
|
# to define a job.
|
|
|
|
# The EXPR-PATH environment variable must be set with the local path.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
URL=http://localhost:3000
|
|
|
|
USERNAME="admin"
|
|
|
|
PASSWORD="admin"
|
|
|
|
PROJECT_NAME="trivial"
|
|
|
|
JOBSET_NAME="trivial"
|
|
|
|
EXPR_PATH=${EXPR_PATH:-}
|
|
|
|
|
|
|
|
if [ -z $EXPR_PATH ]; then
|
|
|
|
echo "Environment variable EXPR_PATH must be set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mycurl() {
|
|
|
|
curl --referer $URL -H "Accept: application/json" -H "Content-Type: application/json" $@
|
|
|
|
}
|
|
|
|
|
|
|
|
cat >data.json <<EOF
|
|
|
|
{ "username": "$USERNAME", "password": "$PASSWORD" }
|
|
|
|
EOF
|
|
|
|
mycurl -X POST -d '@data.json' $URL/login -c hydra-cookie.txt
|
|
|
|
|
|
|
|
cat >data.json <<EOF
|
|
|
|
{
|
|
|
|
"displayname":"Trivial",
|
2018-11-08 07:43:39 +00:00
|
|
|
"enabled":"1",
|
|
|
|
"visible":"1"
|
2018-05-18 15:49:32 +01:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
mycurl --silent -X PUT $URL/project/$PROJECT_NAME -d @data.json -b hydra-cookie.txt
|
|
|
|
|
|
|
|
cat >data.json <<EOF
|
|
|
|
{
|
|
|
|
"description": "Trivial",
|
|
|
|
"checkinterval": "60",
|
|
|
|
"enabled": "1",
|
|
|
|
"visible": "1",
|
|
|
|
"keepnr": "1",
|
|
|
|
"nixexprinput": "trivial",
|
|
|
|
"nixexprpath": "trivial.nix",
|
|
|
|
"inputs": {
|
|
|
|
"trivial": {
|
|
|
|
"value": "$EXPR_PATH",
|
|
|
|
"type": "path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
mycurl --silent -X PUT $URL/jobset/$PROJECT_NAME/$JOBSET_NAME -d @data.json -b hydra-cookie.txt
|