3

我正在使用 Github Action CI/CD 工作流来自动化构建、测试、部署步骤。为了成功构建项目,我需要包含一个秘密变量(在设置中定义)以写入 application.properties 文件。但是,在构建此变量时在文件中找不到。这是工作流程 yml 文件

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'
4

0 回答 0