Answers: <p>The problem is that an official Docker image of phpstan uses ENTRYPOINT [&quot;phpstan&quot;] and the Gitlab runner call the image with &quot;sh -c&quot; command. You can override the default entry point (<a href="https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#overriding-the-entrypoint-of-an-image" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#overriding-the-entrypoint-of-an-image</a>):</p>
  <pre><code>phpstan:
    stage: check
    image: 
      name: ghcr.io/phpstan/phpstan
      entrypoint: [&quot;&quot;]
    script:
      - phpstan analyse
  </code></pre>
  <p>I recommend to use a Docker image for phpstan with concrete version (don't use latest tag).</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-10T22:44:56.033Z
Answers: It is important to keep the original arguments to phpstan: `phpstan analyse --no-progress --error-format gitlab > phpstan.json`.
Answers: Roger Dueck
Answers: CC BY-SA 4.0
Answers: 2022-07-20T15:59:16.970Z
Answers: 2022-07-20T15:59:16.970Z
Answers: jakub.frajt
Body: <p>I have tried to start using phpstan pipeline on gitlab according to <a href="https://www.tremplin-numerique.org/en/how-to-create-a-gitlab-ci-pipeline-to-statically-analyze-php-projects" rel="nofollow noreferrer">this guide</a>.</p>
  <p>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.</p>
  <p>Here is my .gitlab-ci.yml file:</p>
  <pre><code>stages:
    - check
  
  phpstan:
    stage: check
    image: ghcr.io/phpstan/phpstan
    script:
      - analyse --no-progress --error-format gitlab &gt; phpstan.json
  </code></pre>
  <p>And here is the pipeline output:</p>
  <pre><code>Running with gitlab-runner 15.2.0~beta.17.g34ae4a68 (34ae4a68)
    on blue-5.shared.runners-manager.gitlab.com/default -AzERasQ
  Preparing the &quot;docker+machine&quot; 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 &quot;$CI_PRE_CLONE_SCRIPT&quot;
  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 &quot;step_script&quot; 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 &quot;sh&quot; is not defined.  
                              
  Cleaning up project directory and file based variables
  00:01
  ERROR: Job failed: exit code 1
  </code></pre>
  
Tags: <continuous-integration><gitlab><pipeline>
Title: Setting up gitlab phpstan pipeline
UserDisplayName: Kyborek
ThreadText: # Setting up gitlab phpstan pipeline
  
  (Asked by: username_0 on 2022-07-20)
  
  I have tried to start using phpstan pipeline on gitlab according to [this guide](https://www.tremplin-numerique.org/en/how-to-create-a-gitlab-ci-pipeline-to-statically-analyze-php-projects).
  
  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
  
  ```
  
  **Tags:** continuous-integration, gitlab, pipeline
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-20. Score: 3 | Accepted answer
  
  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).
  
  > **Comments:**
  > **username_2**: It is important to keep the original arguments to phpstan: `phpstan analyse --no-progress --error-format gitlab > phpstan.json`.  
  
  ---
  
  