Search code examples
gitlabgitlab-ci

Gitlab CI/CD variable substitution in my appSettings.json


I'm using Gitlab CI/CD to deploy my .netcore application to AWS Beanstalk. How can I update the appSettings.json values in my .netcore application when deploying to different environments using variables defined in my CI/CD pipeline settings?

Azure DevOps has a JSON variable substitution feature which I really liked.

GitHub Actions can also hook into this feature

How can I achieve this with Gitlab CI/CD?

I want to use this method of deployment because

  1. I won't have to store sensitive production config values in my repository. Values will be updated by Masked variables setup in the CI/CD Pipeline.
  2. I don't have to rebuild my artefacts every time I deploy to a new environment.

If this can't be done in Gitlabs, whats the recommended best practice?

thanks


Solution

  • I do something similar here with gitlab and the solution was to build a shell script that replaces some string from variable values before starting the deploy job

    something like this

    script:
      - sed -i 's/STRING_TO_REPLACE/$GITLAB_VARIABLE/g' file.json
    

    Just pay attention to escape json quotes correctly to make this possible