base_url=$(echo "$JIRA_URL" | awk -F'/' '{print $3}')
jira_link=$(git rev-list --format=%B --max-count=1 HEAD | grep -io "http[s]*://$base_url/" || true)
if [[ -n $jira_link ]]; then
- lf-echo-error 'Remove JIRA URLs from commit message'
- lf-echo-error 'Add jira references as: Issue: <JIRAKEY>-<ISSUE#>, instead of URLs'
+ lf-echo-stderr "${FUNCNAME[0]}(): ERROR: JIRA URL found in commit message"
+ lf-echo-stderr 'Add jira references as: Issue: <JIRAKEY>-<ISSUE#>, instead of URLs'
return 1
fi
+ else
+ echo "${FUNCNAME[0]}(): WARNING: JIRA_URL not set, continuing anyway"
fi
return 0
}
function lf-jjb-check-ascii()
{
if [[ ! -d "jjb" ]]; then
- lf-echo-error "${FUNCNAME[0]}(): ERROR: missing jjb directory"
- lf-echo-error "This function can only be run from top of global-jjb directory"
+ lf-echo-stderr "${FUNCNAME[0]}(): ERROR: missing jjb directory"
+ lf-echo-stderr "This function can only be run from top of global-jjb directory"
return 1
fi
if LC_ALL=C grep -I -r '[^[:print:][:space:]]' jjb/; then
- lf-echo-error "${FUNCNAME[0]}(): ERROR: Found YAML files containing non-printable characters."
+ lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Found YAML files containing non-printable characters."
return 1
fi
echo "${FUNCNAME[0]}(): INFO: All JJB YAML files contain only printable ASCII characters"
- ../shell/python-tools-install.sh
- shell: !include-raw:
- ../shell/sudo-logs.sh
+ - shell: !include-raw:
+ - ../shell/job-cost.sh
- shell: !include-raw:
- ../shell/logs-deploy.sh
- shell: !include-raw:
files:
- file-id: clouds-yaml
target: "$HOME/.config/openstack/clouds.yaml"
- - shell: |
- #!/bin/bash -l
- echo "Deleting $OS_STACK_NAME"
- lftools openstack --os-cloud "$OS_CLOUD" stack delete "$OS_STACK_NAME"
+ - shell: !include-raw-escape: ../shell/openstack-stack-delete.sh
mark-unstable-if-failed: false
--- /dev/null
+---
+features:
+ - |
+ Generate Job cost information Each job it will archive a CSV file
+ (cost.csv). It will contain a single CSV record containing the following
+ fields: JobName , BuildNumber , Date , InstanceType , Uptime , Cost1 , Cost2
+ The Date field can be sorted as a string and is readable by your favorite
+ spreadsheet.
+ The Date/Time is GMT.
+ The Uptime is uptime of the build agent (secs).
+ The Cost1 field is the cost($$) of the build node & Cost2 is cost associated
+ with the stack. If the job is not a Openstack job, then Cost2 is '0'. The
+ project cost file will based on the year (cost-2019.csv).
+
+upgrade:
+ - |
+ The openstack-stack-delete.sh script installs the latest tagged version of
+ lftools and it uses that to get the stack cost. Any version of lftools >=
+ v0.29.0 will contain the required changes to get the stack cost.
GERRIT_TOPIC="$(echo "$GERRIT_TOPIC" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
GERRIT_USER="$(echo "$GERRIT_USER" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
REVIEWERS_EMAIL="$(echo "$REVIEWERS_EMAIL" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
+job=$JOB_NAME/$BUILD_NUMBER
CHANGE_ID=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
limit:1 owner:self is:open project:"$PROJECT" \
awk '{ print $2 }')
if [ -z "$CHANGE_ID" ]; then
- git commit -sm "$GERRIT_COMMIT_MESSAGE"
+ git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}"
else
- git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Change-Id: $CHANGE_ID"
+ git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}\nChange-Id: $CHANGE_ID"
fi
git status
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> build-cost.sh"
+
+set -euf -o pipefail
+
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+
+lf-activate-venv python-openstackclient
+
+if [[ -z ${JOB_NAME:-} ]]; then
+ lf-echo-error "Required Env Variable Unset/Empty: JOB_NAME"
+ exit 1
+fi
+
+# Get the cost of the Openstack agents. The 'stack-cost' file is created when
+# the 'lftools openstack stack cost' command is called from
+# 'openstack-stack-delete.sh' script. The 'stack-cost' file will only be created
+# if this is an openstack job.
+if [[ -f stack-cost ]]; then
+ echo "DEBUG: $(cat stack-cost)"
+ echo "INFO: Retrieving Stack Cost..."
+ if ! stack_cost=$(fgrep "total: " stack-cost | awk '{print $2}'); then
+ echo "ERROR: Unable to retrieve Stack Cost, continuing anyway"
+ stack_cost=0
+ fi
+else
+ echo "INFO: No Stack..."
+ stack_cost=0
+fi
+
+# Retrieve the current uptime (in seconds)
+uptime=$(cat /proc/uptime | awk '{print $1}')
+# Convert to integer by truncating fractional part' and round up by one
+((uptime=${uptime%\.*}+1))
+
+instance_type=$(curl -s http://169.254.169.254/latest/meta-data/instance-type)
+
+echo "INFO: Retrieving Pricing Info for: $instance_type"
+url="https://pricing.vexxhost.net/v1/pricing/$instance_type/cost?seconds=$uptime"
+jason_block=$(curl -s $url)
+
+cost=$(jq .cost <<< $jason_block)
+resource=$(jq .resource <<< $jason_block | tr -d '"')
+
+# Archive the cost date
+mkdir -p $WORKSPACE/archives/cost
+
+echo "INFO: Archiving Costs"
+
+# Set the timestamp in GMT
+# This format is readable by spreadsheet and is easily sortable
+date=$(TZ=GMT date +'%Y-%m-%d %H:%M:%S')
+
+cat << EOF > $WORKSPACE/archives/cost.csv
+$JOB_NAME,$BUILD_NUMBER,$date,$resource,$uptime,$cost,$stack_cost
+EOF
+
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> openstack-stack-delete.sh"
+
+set -eufo pipefail
+
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+
+lf-activate-venv lftools[openstack] python-openstackclient
+
+echo "INFO: Retrieving stack cost for: $OS_STACK_NAME"
+if ! lftools openstack --os-cloud $OS_CLOUD stack cost $OS_STACK_NAME > stack-cost; then
+ echo "WARNING: Unable to get stack costs, continuing anyway"
+ echo "total: 0" > stack-cost
+else
+ echo "DEBUG: Successfully retrieved stack cost: $(cat stack-cost)"
+fi
+
+# Delete the stack even if the stack-cost script fails
+lftools openstack --os-cloud "$OS_CLOUD" stack delete "$OS_STACK_NAME" \
+ | echo "INFO: $(cat)"
+