1

I have tried to start using phpstan pipeline on gitlab according to this guide.

The problem is that the pipeline does not work at all (Command 'sh' is not defined) and i don't know how to fix it.

Here is my .gitlab-ci.yml file:

stages:
  - check

phpstan:
  stage: check
  image: ghcr.io/phpstan/phpstan
  script:
    - analyse --no-progress --error-format gitlab > phpstan.json

And here is the pipeline output:

Running with gitlab-runner 15.2.0~beta.17.g34ae4a68 (34ae4a68)
  on blue-5.shared.runners-manager.gitlab.com/default -AzERasQ
Preparing the "docker+machine" executor
Using Docker executor with image ghcr.io/phpstan/phpstan ...
Pulling docker image ghcr.io/phpstan/phpstan ...
Using docker image sha256:797d91431d4ecb9c7c570d793db215dec2ae01f942b85e4e6e7cf4e07d07c8f2 for     ghcr.io/phpstan/phpstan with digest     ghcr.io/phpstan/phpstan@sha256:ac693ee977b314976226205631cd9071364f6c84b3b113f0c9404f9d4747a0b5     ...
Preparing environment
00:01
Running on runner--azerasq-project-37231833-concurrent-0 via runner-azerasq-shared-1658326011-    484bb33b...
Getting source from Git repository
00:03
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/balikobot/BalikobotAdmin/.git/
Created fresh repository.
Checking out e4512b17 as feature/ci-pipeline...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:797d91431d4ecb9c7c570d793db215dec2ae01f942b85e4e6e7cf4e07d07c8f2 for     ghcr.io/phpstan/phpstan with digest     ghcr.io/phpstan/phpstan@sha256:ac693ee977b314976226205631cd9071364f6c84b3b113f0c9404f9d4747a0b5     ...
                            
  Command "sh" is not defined.  
                            
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

1 Answer 1

3

The problem is that an official Docker image of phpstan uses ENTRYPOINT ["phpstan"] and the Gitlab runner call the image with "sh -c" command. You can override the default entry point (https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#overriding-the-entrypoint-of-an-image):

phpstan:
  stage: check
  image: 
    name: ghcr.io/phpstan/phpstan
    entrypoint: [""]
  script:
    - phpstan analyse

I recommend to use a Docker image for phpstan with concrete version (don't use latest tag).

1
  • It is important to keep the original arguments to phpstan: phpstan analyse --no-progress --error-format gitlab > phpstan.json. Oct 10, 2023 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.