Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If Bicep returns a non-0 exit code (e.g. there are any build errors), not propagating output #28259

Open
johnnyreilly opened this issue Jan 28, 2024 · 1 comment
Labels
Auto-Assign Auto assign by bot Azure Deployments az deployment/bicep/stack/deployment-scripts/ts/group export bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team.

Comments

@johnnyreilly
Copy link

johnnyreilly commented Jan 28, 2024

Describe the bug

@anthony-c-martin of the Bicep team asked me to raise this issue here:

Azure/bicep#11960 (comment)

This issue being experienced is that when az bicep lint fails (returns a non-0 exit code) no output is produced.

Related command

Consider the following command that lints a Bicep module and outputs to a bicep.sarif file:

az bicep lint --file ./infra/main.bicep --diagnostics-format sarif > bicep.sarif

This works well when it comes to lints that exit with 0 (only warnings). Output is produced, this is as desired. However if the linting fails / exits with non-0 then output is not produced. This is a problem as users are not advised as to the problem.

Errors

Haha - it's actually the lack of errors that is the issue!

Issue script & Debug output

Running in the context of GitHub Actions:

      - name: Lint Bicep
        if: github.event_name == 'pull_request'
        uses: azure/CLI@v1
        with:
          inlineScript: |
            az bicep install
            az bicep version
            az bicep lint --file ./infra/main.bicep --diagnostics-format sarif > bicep.sarif
            echo '::warning::Bicep linting results:'
            cat bicep.sarif

With a bicepconfig.json that looks like this:

{
  // See https://aka.ms/bicep/config for more information on Bicep configuration options
  // Press CTRL+SPACE/CMD+SPACE at any location to see Intellisense suggestions
  "analyzers": {
    "core": {
      "rules": {
        "no-unused-vars": {
          "level": "error"
        }
      }
    }
  }
}

And in the main.bicep file an unused variable:

var unusedVar = 1 

This produces no output. See here: https://github.com/johnnyreilly/blog.johnnyreilly.com/actions/runs/7684802835/job/20941714974?pr=817

Error: Error: az cli script failed.
cleaning up container...
MICROSOFT_AZURE_CLI_1706434089539_CONTAINER

Error: az cli script failed.

Expected behavior

By contrast compare with https://github.com/johnnyreilly/blog.johnnyreilly.com/actions/runs/7684722135/job/20941552998 where there was a 0 return code as we dialled the lint rule down from an error to a warning:

{
  "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json",
  "version": "2.1.0",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "bicep"
        }
      },
      "results": [
        {
          "ruleId": "no-unused-vars",
          "message": {
            "text": "Variable \"unusedVar\" is declared but never used. [https://aka.ms/bicep/linter/no-unused-vars]"
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///home/runner/work/blog.johnnyreilly.com/blog.johnnyreilly.com/./infra/main.bicep"
                },
                "region": {
                  "startLine": 19,
                  "charOffset": 5
                }
              }
            }
          ]
        }
      ],
      "columnKind": "utf16CodeUnits"
    }
  ]
}

Regardless of whether exiting with 0 or non-0, az bicep lint should produce output.

Environment Summary

{
  "azure-cli": "2.56.0",
  "azure-cli-core": "2.56.0",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {}
}

Additional context

Read more from the thread here: Azure/bicep#11960 - there's a bunch of things in there

@johnnyreilly johnnyreilly added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jan 28, 2024
@yonzhan
Copy link
Collaborator

yonzhan commented Jan 28, 2024

Thank you for opening this issue, we will look into it.

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot Azure Deployments az deployment/bicep/stack/deployment-scripts/ts/group export Service Attention This issue is responsible by Azure service team. labels Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot Azure Deployments az deployment/bicep/stack/deployment-scripts/ts/group export bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants