5

I'm using GitHub Actions CI/CD workflow to automate the build, test, deploy steps. In order to successfully build the project I need to include a secret variable (defined in the settings) to be written to application.properties file. However, at the time of building this variable is not found on the file. Here's workflow yml file

name: Build and deploy JAR app to Azure Web App - harry-kart-web-api

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:

  compile:
    runs-on: windows-latest
    name: Running Java ${{ matrix.java }} compile
    steps:
    - uses: actions/checkout@v2
    - name: Set up Java version
      uses: actions/setup-java@v1
      with:
        java-version: '11'
    - name: Compile code
      run: mvn compile



  test:
    runs-on: windows-latest
    name: Running tests
    needs: compile
    steps:
      - uses: actions/checkout@v2
      - name: Set up Java version
        uses: actions/setup-java@v1
        with:
          java-version: '11'
      - name: Run unit tests
        run: mvn test

  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    - name: Set up Java version
      uses: actions/setup-java@v1
      with:
        java-version: '11'

    - name: Adding secret
      run: |
          echo $DEV_PROP_FILE >> src/main/resources/application.properties
          cat src/main/resources/application.properties
      shell: bash
      env:
        DEV_PROP_FILE: ${{secrets.AZURE_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY}}

    - name: Build with Maven
      run: mvn clean install

    - name: Upload artifact for deployment job
      uses: actions/upload-artifact@v2
      with:
        name: java-app
        path: '${{ github.workspace }}/target/*.jar'

  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
    - name: Download artifact from build job
      uses: actions/download-artifact@v2
      with:
        name: java-app

    - name: Deploy to Azure Web App
      id: deploy-to-webapp
      uses: azure/webapps-deploy@v2
      with:
        app-name: 'harry-kart-web-api'
        slot-name: 'production'
        publish-profile: ${{ secrets.AzureAppService_PublishProfile_c1d922ca006d4e828ca9710ff6d19933 }}
        package: '*.jar'
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
TheLoneWolf91193
  • 415
  • 7
  • 19

1 Answers1

0

Put your variable inside of "", if you want to write them as new line to the properties.

echo "$PropertyString" >> path/file.properties

the characters ">>" will write the first part at the end of the document (as new line)

if you want to replace the file contents with yours you have to use:

echo $Property > path/file.properties

this will replace all file contents with the defined property

Variables are replaced for their names before the commands run. I recommend you to read echo command documentation

Rejja Kubzek
  • 81
  • 1
  • 6