firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

Allow running CI component locally #1272

Closed hverlin closed 1 week ago

hverlin commented 1 week ago

Is your feature request related to a problem? Please describe.

Assuming I have the following component defined in templates/my-component

# templates/my-component.yml
---
component-job:
  script: echo job 1

and I am importing with:

# .gitlab-ci.yml

include:
  - component: $CI_SERVER_HOST/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA

or (after GitLab 16.10)

# .gitlab-ci.yml

include:
  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA

I would like this job to work locally (as shown in the test the component section https://docs.gitlab.com/ee/ci/components/#test-the-component)

image

Currently, it fails with the following error as it tries to resolve it from the server

Error: Error: Command failed with exit code 1: git archive --remote=ssh://git@[....]hverlin/gitlab-ci-testing.git 69a491ee216c917d8a64c14bcea64234e5d4def1 templates/my-component.yml
fatal: sent error to the client: git upload-archive: archiver died with error
remote: fatal: no such ref: 69a491ee216c917d8a64c14bcea64234e5d4def1        
remote: git upload-archive: archiver died with error

Describe the solution you'd like I think we could make gitlab-ci-local try to import from local when CI_COMMIT_SHA is used, as it will always fail?

Describe alternatives you've considered Maybe adding a special directive/comment to indicate how to resolve it on local