I am trying to write a bash script to change a string in a class for my azure devops pipeline.But cannot make it work.
Copied the script from https://github.com/Microsoft/appcenter-build-scripts-examples/blob/master/xamarin/app-constants/appcenter-pre-build.sh
my bash attempt:
- Added a bash task (inline script)
- Created an env variable API_URL with value ="https://production.com/api"
My Class to change
namespace Core { public class AppConstant { public const string ApiUrl = "https://production.com/api"; public const string AnotherOne="AAA"; } }
My script
if [ ! -n "$API_URL" ]
then
echo "You need define the API_URL variable"
exit
fi
APP_CONSTANT_FILE=$(Build.SourcesDirectory)/MyProject/Core/AppConstant.cs
if [ -e "$APP_CONSTANT_FILE" ]
then
echo "Updating ApiUrl to $API_URL in AppConstant.cs"
sed -i '' 's#ApiUrl = "[a-z:./]*"#ApiUrl = "'$API_URL'"#' $APP_CONSTANT_FILE
echo "File content:"
cat $APP_CONSTANT_FILE
fi
why does my variable not change? many thanks