cytopia / docker-ansible-lint

Alpine-based multistage-build version of ansible-lint for reproducible usage in CI
MIT License
16 stars 9 forks source link

Does not work with GitLab CI #14

Closed Jamesking56 closed 4 years ago

Jamesking56 commented 4 years ago

Trying to use this on GitLab CI:

.gitlab-ci.yml

ansible-lint:
  image: cytopia/ansible-lint
  stage: lint
  script:
    - ansible-lint -R -x idempotency,ANSIBLE0010 *.yml --nocolor

Output from GitLab CI:

WARNING: Couldn't open sh - No such file or directory
cytopia commented 4 years ago

@Jamesking56 how does GitLab invoke it? Are you able to see the full run command?

DutchessNicole commented 4 years ago

Gitlab checks out the code repository inside a directory in /builds/\<namespace>/\<project name> and tries to cd into it.

From there it'll try to run the script block with any elements passed to it

so given this config:

stages:
  - lint
ansible-linter:
  variables:
    CI_DEBUG_TRACE: "true"
  image: cytopia/ansible-lint
  stage: lint
  tags: ['generic']
  script:
    - ansible-lint inventories/playbook.yml

gitlab starts a docker container, checks out the code as mentioned above, tries to cd to the code directory and that is where it fails. It never gets to the script block where the ansible-lint command is.

cytopia commented 4 years ago

I am adding the option to have it run without any arguments by default (https://github.com/cytopia/docker-ansible-lint/issues/17)

https://github.com/cytopia/docker-ansible-lint/pull/18

DutchessNicole commented 4 years ago
stages:
  - lint

ansible-linter:
  image: cytopia/ansible-lint
  stage: lint
  tags: ['generic']
  script:
    - echo $PATH
    - pwd
    - which ansible-lint
    - ansible-lint inventories/bootstrap.yml
    - ansible-lint inventories/configure.yml

Given the preceding gitlab-ci file, we still get the missing sh lines:

WARNING: Couldn't open sh - No such file or directory
WARNING: Couldn't open sh - No such file or directory

I looked through the linked issues #17 and #18 but I don't quite see how they relate to this issue? Could you elaborate on what the fix would be?

xmariopereira commented 4 years ago

I have the same issue, running in gitlab too.

ndegory commented 4 years ago

I made it work by specifying an entrypoint:

default:
  image:
    name: cytopia/ansible-lint:latest
    entrypoint: ["/bin/sh", "-c"]

stages:
  - lint

ansible-linter:
  stage: lint
  script:
    - ansible-lint *.yaml
  only:
    - merge_requests
    - master
cytopia commented 4 years ago

Thanks @ndegory Is this also working for @Jamesking56 , @DutchessNicole and @xmariopereira ?

Might also be related: https://github.com/cytopia/docker-yamllint/issues/14

Jamesking56 commented 4 years ago

Can confirm setting the entrypoint works :+1:

cytopia commented 4 years ago

I will add this to the README

cytopia commented 4 years ago

Thanks everyone for figuring this out :)

katanacrimson commented 3 years ago

FWIW - gitlab ci only requires an empty entrypoint.

You can just use:

    entrypoint: ['']

And it'll work fine.