.gitlab-ci.yml

11th July 2017 at 11:25am
GitLab
---

variables:
  # Debug and tracing.
  #CI_DEBUG_TRACE: "true"
  #GIT_CURL_VERBOSE: "1"
  #GIT_DEBUG_LOOKUP: "1"
  #GIT_TRACE: "1"
  #GIT_TRACE_PACKET: "1"
  #GIT_TRANSLOOP_DEBUG: "1"
  #GIT_TRANSPORT_HELPER_DEBUG: "1"

  # Our own project variables.
  pkg: "my-awesome-project"
  artifactory_api: "https://artifactory.local"
  artifactory_repo: "test-rpm-local"
  artifactory_user: "gitlab-ci"
  #artifactory_secret is defined under Settings > CI/CD Pipelines > Secret Variables.

image: nicolaw/docker-shellci

# Run stages in the following order:
stages:
  - test
  - build
  - deploy

# Build tarball and RPM artifacts.
build:
  stage: build
  script:
    - VERSION="$(< VERSION)"
    - mkdir -pv "build/${pkg}-${VERSION%.*}"
    - cp -v *.* Makefile CHANGELOG LICENSE "build/${pkg}-${VERSION%.*}"
    - tar -C build/ -zvcf "${pkg}-${VERSION}.tar.gz" "${pkg}-${VERSION%.*}"
    - >
      rpmbuild -ba "build/${pkg}-${VERSION%.*}/${pkg}.spec"
      --define "name ${pkg}"
      --define "version ${VERSION%.*}"
      --define "release ${VERSION##*.}"
      --define "_sourcedir $PWD"
      --define "_rpmdir $PWD"
      --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"
  artifacts:
    untracked: true
    paths:
      - build/
      - "*.rpm"
      - "*.tar.gz"
    when: on_success
    expire_in: 1 week

# Run very simple unit tests and extract test coverage.
unit tests:
  stage: test
  script:
    - make test
  coverage: '/\d+\.\d+% coverage/'

# Deploy RPM artifacts to Arficactory staging YUM repository.
deploy to staging:
  stage: deploy
  when: manual
  variables:
    environment: staging
  environment:
    name: staging
  script: &deploy_to_artifactory
    - >
      for rpm in *.rpm ; do
      curl "-u${artifactory_user}:${artifactory_secret}"
      -XPUT "${artifactory_api}/${artifactory_repo}/${environment}/${rpm##*/}"
      -T "${rpm}" ;
      done
    - curl "-u${artifactory_user}:${artifactory_secret}"
      -POST "${artifactory_api}/${artifactory_repo}?path=${environment}&async=1"

# Deploy RPM artifacts to Arficactory production YUM repository.
deploy to production:
  stage: deploy
  when: manual
  variables:
    environment: production
  environment:
    name: production
  script: *deploy_to_artifactory

Related