[2020-02] Bump msbuild to track mono-2019-12 (#19661)
[mono-project.git] / eng / common / pipeline-logging-functions.sh
blob33c3f0d8072a456b3f7e806c5267cffce2798ba9
1 #!/usr/bin/env bash
3 function Write-PipelineTelemetryError {
4 local telemetry_category=''
5 local force=false
6 local function_args=()
7 local message=''
8 while [[ $# -gt 0 ]]; do
9 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
10 case "$opt" in
11 -category|-c)
12 telemetry_category=$2
13 shift
15 -force|-f)
16 force=true
18 -*)
19 function_args+=("$1 $2")
20 shift
23 message=$*
25 esac
26 shift
27 done
29 if [[ $force != true ]] && [[ "$ci" != true ]]; then
30 echo "$message" >&2
31 return
34 message="(NETCORE_ENGINEERING_TELEMETRY=$telemetry_category) $message"
35 function_args+=("$message")
36 if [[ $force == true ]]; then
37 function_args+=("-force")
40 Write-PipelineTaskError $function_args
43 function Write-PipelineTaskError {
44 if [[ $force != true ]] && [[ "$ci" != true ]]; then
45 echo "$@" >&2
46 return
49 local message_type="error"
50 local sourcepath=''
51 local linenumber=''
52 local columnnumber=''
53 local error_code=''
55 while [[ $# -gt 0 ]]; do
56 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
57 case "$opt" in
58 -type|-t)
59 message_type=$2
60 shift
62 -sourcepath|-s)
63 sourcepath=$2
64 shift
66 -linenumber|-ln)
67 linenumber=$2
68 shift
70 -columnnumber|-cn)
71 columnnumber=$2
72 shift
74 -errcode|-e)
75 error_code=$2
76 shift
79 break
81 esac
83 shift
84 done
86 local message="##vso[task.logissue"
88 message="$message type=$message_type"
90 if [ -n "$sourcepath" ]; then
91 message="$message;sourcepath=$sourcepath"
94 if [ -n "$linenumber" ]; then
95 message="$message;linenumber=$linenumber"
98 if [ -n "$columnnumber" ]; then
99 message="$message;columnnumber=$columnnumber"
102 if [ -n "$error_code" ]; then
103 message="$message;code=$error_code"
106 message="$message]$*"
107 echo "$message"
110 function Write-PipelineSetVariable {
111 if [[ "$ci" != true ]]; then
112 return
115 local name=''
116 local value=''
117 local secret=false
118 local as_output=false
119 local is_multi_job_variable=true
121 while [[ $# -gt 0 ]]; do
122 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
123 case "$opt" in
124 -name|-n)
125 name=$2
126 shift
128 -value|-v)
129 value=$2
130 shift
132 -secret|-s)
133 secret=true
135 -as_output|-a)
136 as_output=true
138 -is_multi_job_variable|-i)
139 is_multi_job_variable=$2
140 shift
142 esac
143 shift
144 done
146 value=${value/;/%3B}
147 value=${value/\\r/%0D}
148 value=${value/\\n/%0A}
149 value=${value/]/%5D}
151 local message="##vso[task.setvariable variable=$name;isSecret=$secret;isOutput=$is_multi_job_variable]$value"
153 if [[ "$as_output" == true ]]; then
154 $message
155 else
156 echo "$message"
160 function Write-PipelinePrependPath {
161 local prepend_path=''
163 while [[ $# -gt 0 ]]; do
164 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
165 case "$opt" in
166 -path|-p)
167 prepend_path=$2
168 shift
170 esac
171 shift
172 done
174 export PATH="$prepend_path:$PATH"
176 if [[ "$ci" == true ]]; then
177 echo "##vso[task.prependpath]$prepend_path"