Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packer build from a Gitlab pipeline

I am trying to execute my packer build into a Gitlab pipeline, i didn't find examples on the internet but i have seen there is a docker image, so i was hoping this yaml would do the job:

image: hashicorp/packer

stages:
  - build

build:
  stage: build
  script:
    - echo "Hello world"
    - packer build ./definition.json
  only:
    - master

But i don't understand the behavior, the CI pull the image, clone the repo, then it ends up like this:

Skipping Git submodules setup
Usage: packer [--version] [--help] <command> [<args>]

Available commands are:
    build       build image(s) from template
    console     creates a console for testing variable interpolation
    fix         fixes templates from old versions of packer
    inspect     see components of a template
    validate    check that a template is valid
    version     Prints the Packer version

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

Available commands are:
    build       build image(s) from template
    console     creates a console for testing variable interpolation
    fix         fixes templates from old versions of packer
    inspect     see components of a template
    validate    check that a template is valid
    version     Prints the Packer version

ERROR: Job failed: exit code 127

It doesn't even print my echo Hello World, and it prints 2 times how i should iterract with the CLI, why this behavior?

like image 662
Ludo Avatar asked Oct 25 '19 19:10

Ludo


People also ask

What is a packer build?

The packer build command takes a template and runs all the builds within it in order to generate a set of artifacts. The various builds specified within a template are executed in parallel, unless otherwise specified. And the artifacts that are created will be outputted at the end of the build.

How does GitLab CI CD pipeline work?

A pipeline is usually triggered by a source code repository. Changes in code activate a notification in the CI/CD pipeline tool, which operates the corresponding pipeline. Other triggers you might see frequently include user-initiated or automatically scheduled workflows, as well as results of other pipelines.

Can you have multiple pipelines in GitLab?

Yes, you can use the rules syntax. You can use this in combination with regex for commit message, ci_pipeline_source or any other available CI variables. In doing this you can compose the jobs/pipelines you want in its own yml file and then define the jobs using those templates in the gitlab-ci.


1 Answers

I found how to fix it, i had to change:

image: hashicorp/packer

into:

image:
  name: hashicorp/packer
  entrypoint:
    - '/usr/bin/env'
    - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
like image 197
Ludo Avatar answered Nov 15 '22 08:11

Ludo