Skip to content

eng/common/pipeline-logging-functions.sh: line 44: force: unbound variable #5387

Closed

Description

@hughbe

Running ./build.sh from the root of dotnet/winforms, we get the following error (you need to remove dotnet-api-docs_netcoreapp3.0 from global.json)

hugh@Hughs-MacBook-Air winforms % ./build.sh  
/Users/hugh/Documents/GitHub/winforms/eng/common/init-tools-native.sh: line 91: native_assets[$key]: bad array subscript
No native tools defined in global.json
  Determining projects to restore...
  All projects are up-to-date for restore.
Unknown CPU i386 detected, treating it as x64
dotnet-install: .NET Core Runtime version 5.0.0-preview.5.20230.3 is already installed.
dotnet-install: Adding to current process PATH: `/Users/hugh/Documents/GitHub/winforms/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Installation finished successfully.

Build FAILED.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.21
/Users/hugh/Documents/GitHub/winforms/eng/common/pipeline-logging-functions.sh: line 44: force: unbound variable

Inspecting the code, I think we may have a problem:

function Write-PipelineTelemetryError {
  local telemetry_category=''
  local force=false
  local function_args=()
  local message=''
  while [[ $# -gt 0 ]]; do
    opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
    case "$opt" in
      -category|-c)
        telemetry_category=$2
        shift
        ;;
      -force|-f)
        force=true
        ;;
      -*)
        function_args+=("$1 $2")
        shift
        ;;
      *)
        message=$*
        ;;
    esac
    shift
  done

  if [[ $force != true ]] && [[ "$ci" != true ]]; then
    echo "$message" >&2
    return
  fi

  message="(NETCORE_ENGINEERING_TELEMETRY=$telemetry_category) $message"
  function_args+=("$message")
  if [[ $force == true ]]; then
    function_args+=("-force")
  fi

  Write-PipelineTaskError $function_args
}

function Write-PipelineTaskError {
  if [[ $force != true ]] && [[ "$ci" != true ]]; then
    echo "$@" >&2
    return
  fi
  ...
}

It looks like Write-PipelineTaskError is called with -force as a function argument but Write-PipelineTaskError expects it as a variable?

Activity

  1. missymessa commented on May 15, 2020

    @missymessa
    Member

    Attempted to repro this on my Windows machine with git bash, and was unable to. Was calling Write-PipelineTelemetryError -force and saw that -force was being recognized as true when it was being passed into Write-PipelineTaskError.

    Should try to get a repro on a macOS.

  2. akoeplinger commented on May 19, 2020

    @akoeplinger
    Member

    I'm seeing the same in the dotnet/runtime build on macOS 10.15 when an error happens. macOS now uses zsh as the default shell so you might be able to get a repro on Windows/Linux by using that shell.

  3. removed their assignment
    on May 19, 2020
  4. chcosta commented on May 19, 2020

    @chcosta
    Member

    I'm not able to repro this (haven't tried on OSX)

    This is the confusing part of the error (to me).

    /Users/hugh/Documents/GitHub/winforms/eng/common/init-tools-native.sh: line 91: native_assets[$key]: bad array subscript
    No native tools defined in global.json
    

    This would seem to imply that your global.json looks something like this...

    {
      "tools": {
        "dotnet": "5.0.100-preview.5.20251.2",
        "runtimes": {
          "dotnet": [
            "$(MicrosoftNETCoreAppPackageVersion)"
          ]
        }
      },
      "sdk": {
        "version": "5.0.100-preview.5.20251.2"
      },
      "msbuild-sdks": {
        "Microsoft.DotNet.Arcade.Sdk": "5.0.0-beta.20261.9",
        "Microsoft.DotNet.CMake.Sdk": "5.0.0-beta.20256.5",
        "Microsoft.DotNet.Helix.Sdk": "5.0.0-beta.20261.9",
        "FIX-85B6-MERGE-9C38-CONFLICT": "1.0.0",
        "Microsoft.NET.Sdk.IL": "5.0.0-preview.6.20264.1"
      },
      "native-tools": {
      }
    }
    

    It would be unexpected to have an empty "native-tools" section and not just delete the section entirely.

  5. hughbe commented on May 19, 2020

    @hughbe
    ContributorAuthor

    Oh try removing the entire section of native-tools, I can still repro this

  6. chcosta commented on May 19, 2020

    @chcosta
    Member

    I can't repro this specifically in the winforms repo, but it's easy enough to manufacture a repro and see what is happening. I'll prepare a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions