Code Monkey home page Code Monkey logo

gitlab-ci-user-specific-job's Introduction

Gitlab CI restrict job only for predefined users

Gitlab CI demo for job that should run only when specific user runs the pipeline.

This is to demonstrate a job, that will appear only if the pipelines was triggered by one of the predefined users.

Check .gitlab-ci.yml

This repository is mirrored to Gitlab, so you can check the pipelines.

How it works

Variables can be defined either directly in the .gitlab-ci.yml file or in CI/CD variables in settings to prevent overriding by developers.

Be careful, there is no easy way to prevent developers from editing .gitlab-ci.yml file, to allow job to run even without permissions.

Demo 1

$ALLOWED_USERNAME variable can contain single username - there is == operator and if pipeline is triggered by this user, job will appear.

Demo 2

$ALLOWED_USERNAMES variable can contain multiple usernames divided by | (it is regular expression) - there is =~ operator and if pipeline is triggered any of the users, job will appear.

Demo 3

$ALLOWED_USERNAMES variable can contain multiple usernames. It is a little different from Demo 2 in the way that this job will always appear, but if username is not allowed, the job will fail and not continue.

Motivation

Restrict access to deploy job only for some users.

Goal is to replicate Gitlab CI Protected Environments, as this feature is for premium plan only - therefore not available for everyone.

gitlab-ci-user-specific-job's People

Contributors

janmikes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.