Debugging a gitlab CI build

I’m trying to run a build with Gitlab CI using the community packer docker image:

My .gitlab-ci.yml looks like so:

image: hashicorp/packer:light

  - build

  stage: build
    - build -var-file variables.json centos-6.6-x86_64.json # vars are set in gitlab itself
    - docker

Unfortunately, the build doesn’t work, and just seems to print the usage for packer, which indicates that the command isn’t running correctly:

gitlab-ci-multi-runner 1.1.2 (78b3f82)
Using Docker executor with image hashicorp/packer:light ...
Pulling docker image hashicorp/packer:light ...

Running on runner-36f42261-project-326-concurrent-0 via gitlabrunner-3...
Cloning repository...
Cloning into '/builds/devops/packer-ami'...
Checking out 52014387 as ci_build...
Note: checking out '52014387c33a80ba117d0dd6860d4aa34cf98fec'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 5201438... HArd to debug this nonsense

usage: packer [--version] [--help] <command> [<args>]

Available commands are:
    build       build image(s) from template
    fix         fixes templates from old versions of packer
    inspect     see components of a template
    push        push a template and supporting files to a Packer build service
    validate    check that a template is valid
    version     Prints the Packer version

ERROR: Build failed: exit code 1

This kinda infers that I’m running the script wrong. The entrypoint for the packer docker container is set to /sbin/packer so the script seems fine, it’s as if something else is being run before the actual script inside the docker container.

Problem is, I don’t know what it’s running because I can’t seem to get a reasonable debug log. I’ve run the gitlab-runner in debug mode and I’m still none the wiser. I guess I have 2 questions:

  • What actually runs inside the docker container on the runner?
  • How can I better debug this build error?

I have seen this detached head thing occur even when using a basic shell gitlab runner (not docker).

I think it’s a momentary glitch and specific to your git version. When I saw it, it was git 2.7 client.

Debian Jessie is something even more ancient and glitching (2.1 I think).

Your git version on the runner is?


This is CentOS 7, version 1.8 (so really old!)

I’ll try upgrade git version and see if that helps.

Upgraded git to version 2.8, didn’t make a difference :frowning:

What if you add a cd command to your .gitlab-ci.yml script, and then go to that folder and zap it and let git re-create it.

Hello, the detached HEAD is on purpose, Jenkins does this the same way. Reason. Say two pushes happen very quickly one after another, each of which start a pipeline. GitLabCI needs some time to set up stuff, so if would just check out the branch, both pipelines would just build the same commit, which is useless. Jenkins normally serializes builds, so it is not needed most of the time. GitLabCI happily does multiple builds in parallel for the same branch.

Concerning packet: does invoking “version” run successfully?