title: How does the syntax to specify file type changes in Gitlab's CI rules work?
body: <p>My file structure consits of 2 main directories, <code>resources</code> and <code>src</code>, <code>resources</code> has images in a subdirectory, and various json files. <code>src</code> has many nested directories with <code>.ts</code> files in each:</p>
  <pre><code>├── package.json
  ├── package-lock.json
  ├── README.md
  │ 
  ├── .docker
  │   ├── Dockerfile
  │   └── aBashScript.sh
  │ 
  ├── resources
  │   ├── data.json
  │   └── images
  │       └── manyimages.png
  │
  ├── src
  │   ├── subdirectory1
  │   └── NestedDirectories
  │
  ├── .gitlab-ci.yml
  ├── tsconfig.eslint.json
  ├── tsconfig.json
  ├── eslintrc.json
  └── prettierrc.json
  </code></pre>
  <p>My <code>gitlab-ci.yml</code> has two stages, <code>build</code> and <code>deploy</code><br />
  <strong>What I want:</strong><br />
  1- If it's a commit on branches &quot;main&quot; or &quot;dev&quot; and If anything that affects the actual project changes, run <code>build</code>.<br />
  That is anything under <code>resources</code>, or <code>src</code> (and their nested directories), the <code>Dockerfile</code>, <code>package.json</code> and <code>package-lock.json</code><br />
  I'd be content with &quot;any <code>.ts</code> file changed&quot; too, since all other criteria is <em>usually</em> only when this happens.<br />
  2- If <code>build</code> ran and it's a commit on the default branch (&quot;main&quot;) then run the <code>deploy</code> stage.<br />
  Also for clarification when I say there's a commit on branch X, I mean as in an accepted merge request, or well an actual change on that branch. At some point in my tinkering it was running on (non accepted) merge requests, but I forgot what I changed to fix that.</p>
  <p><strong>What happens:</strong><br />
  1- If I specify the <code>changes</code> rule on build then it <em>never</em> runs, however even if build doesn't run deploy always runs (if on branch &quot;main&quot;)</p>
  <p><code>.gitlab-ci.yml</code></p>
  <pre class="lang-yaml prettyprint-override"><code>variables:
    IMAGE_TAG: project
  
  stages:
    - build
    - deploy
  
  build_image:
      stage: build
      image: docker:20.10.16
      services:
          - docker:20.10.16-dind
      variables:
          DOCKER_TLS_CERTDIR: &quot;/certs&quot;
      before_script:
          - echo $REGISTRY_PASS | docker login -u $REGISTRY_USER --password-stdin
      script:
      - |
          if [[ &quot;$CI_COMMIT_BRANCH&quot; == &quot;$CI_DEFAULT_BRANCH&quot; ]]; then
          tag=&quot;latest&quot;
          echo &quot;Running on default branch '$CI_DEFAULT_BRANCH': tag = '$tag'&quot;
          else
          tag=&quot;$CI_COMMIT_REF_SLUG&quot;
          echo &quot;Running on branch '$CI_COMMIT_BRANCH': tag = $tag&quot;
          fi
      - docker build -f .docker/Dockerfile -t $REPO_NAME:$IMAGE_TAG-$tag .
      - docker push $REPO_NAME:$IMAGE_TAG-$tag
      rules:
          - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == &quot;dev&quot;'
            changes:
              - \*.ts
              - \*.json
              - Dockerfile
  
  deploy:
      stage: deploy
      before_script:
      - chmod SSH_KEY
      script:
      - ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VPS &quot;
          echo $REGISTRY_PASS | docker login -u $REGISTRY_USER --password-stdin &amp;&amp;
          cd project &amp;&amp;
          docker-compose pull &amp;&amp;
          docker-compose up -d&quot;
      rules:
          - if: '$CI_COMMIT_BRANCH == &quot;main&quot;'
  </code></pre>
  <p>This is the most basic one I could cobble up, basically excluding just the readme, but the <code>build</code> stage doesn't run (deploy does run even if build didn't)</p>
  <p>Normally this is something I'd be able to &quot;brute force&quot; figure out myself, but to avoid uselessly modifying my files to test the changes rule, I've only been able to test this when making actual modifications to the project.<br />
  There seems to be a lot of examples from questions and tutorials out there, but I think something is off with my file structure as I've had no luck copying their changes rule</p>