Adam Lyle February 2016

Issues with gitlab-ci stages

I've been working on setting up an automated RPM build and I'd like to perform a simple test on the SPEC file before proceeding with any build steps. The problem I am having is that the job always seems to jump to the deploy stage. Here is the relevant snippet from my .gitlab-ci.yml:

stages:
  - test
  - build
  - deploy

job1:
  stage: test
  script:
    # Test the SPEC file
    - su - newbuild -c "rpmbuild --nobuild -vv ~/rpmbuild/SPECS/package.SPEC"

  stage: build
  script:
    # Install our required packages
    - yum -y install openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel libpng-devel libjpeg-devel ruby

    # Initialize the submodules to build
    - git submodule update --init

    # build the RPM
    - su - newbuild -c "rpmbuild -ba --target=`uname -m` -vv ~/rpmbuild/SPECS/package.SPEC"

  stage: deploy
  script:
    # move the RPM/SRPM
    - mkdir -pv $BUILD_DIR/$RELEASEVER/{SRPMS,x86_64}
    - 'for f in $WORK_DIR/rpmbuild/RPMS/x86_64/*; do  cp -v "$f" $BUILD_DIR/$RELEASEVER/x86_64; done'
    - 'for f in $WORK_DIR/rpmbuild/SRPMS/*; do cp -v "$f" $BUILD_DIR/$RELEASEVER/SRPMS; done'

    # create the repo
    - createrepo -dvp $BUILD_DIR/$RELEASEVER

    # update latest
    - 'if [ $CI_BUILD_REF_NAME == "master" ]; then rm $PROJECT_DIR/latest; ln -sv $(basename $BUILD_DIR) $PROJECT_DIR/latest; fi'
    - 'if [ $CI_BUILD_REF_NAME == "devel" ]; then rm $PROJECT_DIR/latest-dev; ln -sv $(basename $BUILD_DIR) $PROJECT_DIR/latest-dev; fi'

  tags:
    - repos

I've not found any questions or online documentation to properly explain this to me so any help is appreciated!

Answers


st0ph February 2016

You have all stages in one job which does not work. You need to split it up into individual jobs for the three different stages.

Quote from the documentation:

First all jobs of build are executed in parallel.

If all jobs of build succeeds, the test jobs are executed in parallel.

If all jobs of test succeeds, the deploy jobs are executed in parallel.

If all jobs of deploy succeeds, the commit is marked as success.

If any of the previous jobs fails, the commit is marked as failed and no jobs of further stage are executed.

Something like this should work:

stages:
  - test
  - build
  - deploy

do_things_on_stage_test:
  script:
    - do things
  stage: test


do_things_on_stage_build:
  script:
    - do things
  stage: build


do_things_on_stage_deploy:
  script:
    - do things
  stage: deploy

Post Status

Asked in February 2016
Viewed 3,012 times
Voted 13
Answered 1 times

Search




Leave an answer