ethanmdavidson/packer-plugin-git

No evaluation when running in Azure Devops

Closed this issue · 1 comments

Hi,

I was hoping you could help me nail this bug down. So my packer image works locally but when running in Azure Devops Pipelines and using their default checkout I can see that the data sources are not evaluated.

# windows.pkr.hcl
packer {
  required_version = ">= 1.9.0"

  required_plugins {
    azure = {
      version = "2.0.0"
      source  = "github.com/hashicorp/azure"
    }
    ansible = {
      version = "1.1.0"
      source  = "github.com/hashicorp/ansible"
    }
    git = {
      version = "0.4.2"
      source  = "github.com/ethanmdavidson/git"
    }
  }
}

data "git-commit" "cwd-head" {}
data "git-repository" "cwd" {}

locals {
  # publish image only if run on main branch
  do_not_publish = data.git-commit.cwd-head == "main" ? false : true

  # if image is not to be published compute an image version from the current timestamp
  image_version = local.do_not_publish ? formatdate("YYYY.MM.DD", timestamp()) : trim(data.git-repository.cwd.tags[0], "v")
}

source "azure-arm" "build" {
   ...
}

locally I can see the data sources being evaluated correctly:

> packer inspect .
Packer Inspect: HCL2 mode

> input-variables:

> local-variables:

local.do_not_publish: "true"
local.image_version: "2023.09.05"

...

when running in CI the locals are not avaibale:

Packer v1.9.4
Packer Inspect: HCL2 mode

> input-variables:

> local-variables:
...

in CI and local I have packer version 1.9.4.

I guess it is caused by the way Azure checkouts the repository & commit, but running the same checkout command (git checkout --progress --force refs/remotes/origin/<sha>) local it works.

# azure-pipelines.yml
  - stage: validate
    # https://github.com/Microsoft/azure-pipelines-agent/issues/858#issuecomment-457027046
    condition: and(not(contains(variables['Build.SourceVersionMessage'], '[skip ci]')), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
    jobs:
      - job: packer_fmt
        steps:
          - script: |
              cd $(System.DefaultWorkingDirectory)/.
              PACKER_PLUGIN_PATH="./plugins" packer fmt -check=true -recursive=true .
            failOnStderr: "true"
            displayName: packer fmt

      - job: packer_validate
        steps:
          - script: |
              cd $(System.DefaultWorkingDirectory)/.
              packer version
              packer inspect .
              PACKER_PLUGIN_PATH="./plugins" packer validate -evaluate-datasources .
            failOnStderr: "true"
            displayName: packer validate

Do you have any hint that behaviour is caused by?

BR

My bad. I run packer inspect without my plugin configuration (PACKER_PLUGIN_PATH="./plugins") hence inspect could not load the plugins ...