1
votes

I have a project hosted on Gitlab. The project website is inside the pages branch and is a jekyll based site.

My .gitlab-ci.yml looks like

pages:
  script:
  - gem install jekyll
  - jekyll build -d public/
  artifacts:
    paths:
    - public
  only:
    - pages

image: node:latest

cache:
  paths:
    - node_modules/

before_script:
  - npm install -g gulp-cli
  - npm install

test:
  script:
    - gulp test

When I pushed this configuration file to master, the pipeline executed only the test job and not pages job. I thought maybe pushing to master didn't invoke this job because only specifies pages branch. Then I tried pushing to pages branch but to no avail.

How can I trigger the pages job?

3
when should the pages job be executed? on every branch? befor, after or simultan with test? - Rufinus
afair without defined stages docs.gitlab.com/ce/ci/yaml/README.html#stages - pages job only runs when test is completed successfully. - Rufinus
It should run whenever I push/merge to pages branch. And yes even after test was completed, it didn't run. - Chirag Arora

3 Answers

1
votes

You're right to assume that the only constraint makes the job run only on the ref's or branches specified in the only clause.

See https://docs.gitlab.com/ce/ci/yaml/README.html#only-and-except

It could be that there's a conflict because the branch and the job have the same name. Could you try renaming the job to something different just to test?

0
votes

I'd try a couple of things. First, I'd put in this stages snippet at the top of the YML:

stages:
  - test
  - pages

This explicitly tells the CI to run the pages stage after the test stage is successful.

If that doesn't work, then, I'd remove the only tag and see what happens.

0
votes

Complementing @rex answer's:

You can do either:

pages:
  script:
  - gem install jekyll
  - jekyll build -d public/
  artifacts:
    paths:
    - public

Which will deploy your site regardless the branch name, or:

pages:
  script:
  - gem install jekyll
  - jekyll build -d public/
  artifacts:
    paths:
    - public
  only:
  - master # or whatever branch you want to deploy Pages from

Which will deploy Pages from master.

Pls let me know if this helps :)