AZ-400 · Question #611
Hotspot Question You have a GitHub organization that contains a repository and an organizational secret named DB_Credential. You need to build a workflow that will configure a server by using PowerShe
The correct answer is DB_CREDENTIAL: ${{ secrets.DB_Credential }}; configure_server: "$env:DB_CREDENTIAL". This question tests knowledge of GitHub Actions workflow syntax for accessing organizational secrets and executing PowerShell scripts within a job step.
Question
Exhibit
Answer Area
- DB_CREDENTIAL${{ secrets.DB_Credential }}"$DB_CREDENTIAL""$env:DB_CREDENTIAL""$secrets.DB_CREDENTIAL""%DB_CREDENTIAL%""secrets.DB_CREDENTIAL"${{ secrets.DB_Credential }}
- configure_server"$env:DB_CREDENTIAL""$DB_CREDENTIAL""$env:DB_CREDENTIAL""$secrets.DB_CREDENTIAL""%DB_CREDENTIAL%""secrets.DB_CREDENTIAL"${{ secrets.DB_Credential }}
Explanation
This question tests knowledge of GitHub Actions workflow syntax for accessing organizational secrets and executing PowerShell scripts within a job step.
Approach. To use an organizational secret in a GitHub Actions workflow, you reference it using the 'secrets' context with the syntax '${{ secrets.DB_Credential }}' and assign it to an environment variable or pass it directly. The workflow must use 'runs-on' for the runner, a 'steps' block with a 'run' key, and specify 'shell: pwsh' (or 'shell: powershell') to execute PowerShell commands. The secret is accessed via '${{ secrets.DB_Credential }}' in the YAML, and within the PowerShell script it is referenced as an environment variable using '$env:DB_CREDENTIAL'. The job step should map the secret to an environment variable under the 'env' key of the step, e.g., 'env: DB_CREDENTIAL: ${{ secrets.DB_Credential }}', then use '$env:DB_CREDENTIAL' inside the PowerShell run block.
Concept tested. GitHub Actions workflow syntax for organizational secrets, PowerShell shell specification (shell: pwsh), secrets context reference (${{ secrets.SECRET_NAME }}), and environment variable mapping within job steps (env block).
Reference. https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
Topics
Community Discussion
No community discussion yet for this question.
