0

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.

  1. uat-pre-build.sh
  2. dev-pre-build.sh
  3. 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.

1

You appear to want to substitute the string.Empty in your ConfigurationHelper.cs file but as you've discovered, the substitution you're using will never match. You've got ApplicationID = "[-A-Za-z0-9:_./]*". This could match

public static string ApplicationID = "string.Empty";

but since you've explicitly specified the double quote characters in the match pattern they have to be present in the source.

You could try a straight match, ApplicationID = string.Empty. If you really need the complexity of either string.Empty or a quoted string, what about ApplicationID = \(string.Empty|".*"\)

  • Thank you so much. I don't need to work on weekend now. :-) – Sandip Armal Patil Jun 15 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.