Run different pipeline steps from the CLI than from repository hooks

Hey, there!

We started to use Drone last week at my company and we’ve successfully configured a drone pipeline to run our test suite on every push.

We have a separate test suite (smoke tests that run against the deployed app) that we would like to run independently of our main test suite. Specifically, we’d like to schedule it to run periodically. I’ve read that the way to go to achieve that is to use the CLI and a cron job. The thing is that this is a different pipeline than the one that runs on every repo push.

I’m not sure how to solve this, is there a way to specify an alternative .drone.yml in the repo, or maybe parametrize our current pipeline in a way that some steps are run on push and others are run from the cli? (I’ve read the CLI and Conditions docs, but I’m still not sure if there’s a way to combine them to pull this off).

Thanks!

I had exactly the same requirement today.
I thought about something like pipeline but e.g. called tasks:

pipeline:
  backend:
    image: golang
    commands:
      - go get
      - go build
      - go test

  notify:
    image: plugins/slack
    channel: developers
    username: drone

tasks:
  backup:
    image: plugins/s3
    bucket: my-bucket-name
    access_key: a50d28f4dd477bc184fbd10b376de753
    secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
    source: backup/backup.zip
    target: /target/location

And then the steps under tasks could only be triggered with

drone task start <repository> <task_name>

In the example above the <task_name> would be backup.

A task runner like that directly integrated in drone (with the power of all the available plugins) would be awesome in my opinion!

Or is there already a way to run custom tasks?

custom pipeline executions are planned for a future release, but will not be available in the short term.

Thanks for your fast response!

Nice to hear that this feature is planned for a future release.
Till then, I’ll have to do it manually.

@mamiu You can sort of hack around this using deployments:

drone deploy <repo> <build> <environment>

Technically deployments are just custom tasks. You can then have steps in your pipeline that only execute for a particular deployment environment. For example lets say we want to have a nightly task, we could do this:

pipeline:
  build:
    image: golang
    commands:
      - go build
      - go test
    when:
      event:
        excludes: deployment
  nightly:
    image: golang
    commands:
      - echo foo
      - echo bar
    when:
      environment: nightly

Note that a deployment must always be tied to a build, however, you can probably just use the latest successful build for your default branch (eg master).

drone deploy <repo> last <environment>

@facundoolano this should support your use case as well. It certainly isn’t the most optimal approach, and I agree different yaml files would be better (this is also in the works). But hopefully this gives you something you can use today, in the short term.

Cheers

Sounds interesting!

Of course I’ll try it, but as you said, it’s not the most optimal approach.
I’m looking forward to a feature, that solves this use case.

Thanks!

Thanks, I’ll give it a try.

@bradrydzewski I’m trying as you suggested but I can’t seem to make it work. This is what my .drone.yml looks like:

pipeline:
  test:
    image: erlang:20
    network_mode: host
    commands:
      - make test
    when:
      # dont run default tests on smoke events
      event:
        excludes: deployment
      
  # to be used with cli: `drone deploy example/server last smoke --param "HOST=development.example.com"`
  smoke:
    image: erlang:20
    environment:
      - PORT=443
    commands:
      - make smoke
    when:
      environment: smoke

But it seems like the when clause is ignored: it always runs the test step and never runs the smoke one.

I’m using drone 0.7.

Got it, the issue was that the condition should be exclude but I was writing excludes