I have appcenter-pre-build.sh
in which I am executing another script depend on environment type. If environment is UAT then it will execute uat-pre-build.sh
.
Here is appcenter-pre-build.sh
if [ -z "$ENV_TYPE" ]
then
echo "You need define the ENV_TYPE variable in App Center"
exit
fi
echo "ENV_TYPE is : - $ENV_TYPE"
if [ "UAT" = "$ENV_TYPE" ]
then
echo "Environment type : UAT"
ENV_FILE=$APPCENTER_SOURCE_DIRECTORY/ABC/config/uat-pre-build.sh
else
echo "you need to mentioned correct envrionment type"
exit
fi
echo "Environment file : $ENV_FILE"
sh "$ENV_FILE"
I have three different script depends on build environment.
- uat-pre-build.sh
- dev-pre-build.sh
- prod-pre-build.sh
In above script I am reading variable value and trying to assigning it into ConfigurationHelper.cs.
Here is my uat-pre-build.sh
APP_ID=b1a4a39f-4d89-4f04-98d8-2a20eda89aad
# Get ConfigurationHelper.cs from project
APP_CONSTANT_FILE=$APPCENTER_SOURCE_DIRECTORY/helpers/ConfigurationHelper.cs
if [ -e "$APP_CONSTANT_FILE" ]
then
echo "Updating environment configs in AppConstant.cs"
sed -i '' 's#ApplicationID = "[-A-Za-z0-9:_./]*"#ApplicationID = "'$APP_ID'"#' $APP_CONSTANT_FILE
echo "File content:"
cat $APP_CONSTANT_FILE
else
echo "Can not locate $APP_CONSTANT_FILE file"
fi
Here is ConfigurationHelper.cs
public class ConfigurationHelper
{
public static string ApplicationID = string.Empty;
static ConfigurationHelper(){}
}
I am able to execute script but unable to assign APP_ID value from uat-pre-build.sh
to ApplicationID in ConfigurationHelper.cs
. Seems following line is not executing correctly.
sed -i '' 's#ApplicationID = "[-A-Za-z0-9:_./]*"#ApplicationID = "'$APP_ID'"#' $APP_CONSTANT_FILE
Here is output from app center.
[command]/bin/bash
/Users/vsts/agent/2.153.1/work/1/s/ABC.Android/appcenter-pre-build.sh
ENV_TYPE is : - UAT
Environment type : UAT
Environment file : /Users/vsts/agent/2.153.1/work/1/s/ABC/config/uat-pre-build.sh
Updating environment configs in AppConstant.cs
File content:
namespace ABC.Business.Helpers
{
/// <summary>
/// The configuration helper.
/// </summary>
public class ConfigurationHelper
{
public static string ApplicationID = string.Empty;
/// <summary>
/// Initializes static members of the <see cref="ConfigurationHelper"/> class.
/// </summary>
static ConfigurationHelper()
{
}
}
}
Please help me out to resolve this issue.