Promotions

You can use the promotion feature to promote code to a target environment by build number, for example, promote build number 42 to production. Here are some of the benefits of using promotions:

  • Create repeatable deployments
  • Create an audit trail
  • Reduce human error
  • Segregation of duties
  • Revoke developer access to server environments

How it Works

When you promote a build, Drone creates a new build (with a new build number) that inherits its values from the build being promoted. This new build will have an event type is set to promote. You can reference the event type and target environment in your pipeline configuration.

When Drone executes your build, by default, it executes all pipelines and all steps defined in your yaml. You can limit pipeline and step execution by event and by target environment.

  • Limit pipeline execution by target environment:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    kind: pipeline
    type: docker
    name: default
    
    steps:
    - name: test
      image: node
      commands:
      - npm install
      - npm run test
      - npm run bundle
    
    - name: deploy
      image: plugins/ssh
      settings: ...
    
    trigger:
      event:
      - promote
      target:
      - production
    
  • Limit pipeline step execution by target environment:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    kind: pipeline
    type: docker
    name: deploy
    
    steps:
    - name: test
      image: node
      commands:
      - npm install
      - npm run test
      - npm run bundle
    
    - name: deploy
      image: plugins/ssh
      settings: ...
      when:
        event:
        - promote
        target:
        - production
    
  • Create separate pipelines for promotions:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    
    kind: pipeline
    type: docker
    name: build
    
    steps:
    - name: test
      image: node
      commands:
      - npm install
      - npm run test
    
    trigger:
      event:
      - push
      - pull_request
    
    ---
    kind: pipeline
    type: docker
    name: deploy
    
    steps:
    - name: test
      image: node
      commands:
      - npm install
      - npm run test
      - npm run bundle
    
    - name: deploy
      image: plugins/ssh
      settings: ...
    
    trigger:
      event:
      - promote
      target:
      - production
    

How To Promote

You can promote builds using the command line utility:

  • Use the build promote command:

    $ drone build promote <repo> <number> <environment>
    
  • Example promotes build number 42 to staging:

    $ drone build promote octocat/hello-world 42 staging
    
  • Example promotes build number 42 to production:

    $ drone build promote octocat/hello-world 42 production
    

In the above examples we reference staging and production environments, however, the environment is a freeform field. You can use any environment name.