0

I have some stages defined in drone.yml file. Is there a way to specify which stage need to be run through command line parameter? For example: below is my drone.yml file. I want to build buildOnContainer1 and buildOnContainer2 stage separately. So I am looking for a command such as drone exec buildOnContainer1. It only runs the command under buildOnContainer1.

buildOnContainer1:
    image: container1
    pull: true
    commands:
      - npm test:uat
buildOnContainer2:
    image: container2
    pull: true
    commands:
      - npm test:dev
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • this feature has been requested, but nobody has provided a pull request yet. You can star https://github.com/drone/drone/issues/1894#issuecomment-286650012 for updates – Brad Rydzewski May 14 '17 at 12:07

1 Answers1

0

My first thought to implement that granularity level of control is through environment variables.

Drone provides the ability to substitute environment variables at runtime. This gives us the ability to use dynamic build or commit details in our pipeline configuration.

You can pass environment variables to the command line and also to your Drone server using secrets. Check the Drone docs on ENV interpolation and docker exec command

You should build customized images for container1 and container2 to run the commands or skip them based on the values of specific environment variables.

A dirty example would be something like the following .drone.yml:

buildOnContainer1:
  image: container1
  pull: true
  environment:
    - SKIP=${skip.buildOnContainer1}
  commands:
    - ./myscript.sh test:uat
buildOnContainer2:
  image: container2
  pull: true
  environment:
    - SKIP=${skip.buildOnContainer2}
  commands:
    - ./mysqcrypt.sh test:dev

Your custom image should contain a mysqcript.sh bash script in your working directory. The script could check whether the value of the ENVAR SKIP is true or false. If true, it would do nothing. If false is would execute npm command with whatever args you had passed to the script.

Then you could execute the build locally:

drone exec --secret skip.buildOnContainer1=true --secret skip.buildOnContainer2=false
Daniel Cerecedo
  • 6,071
  • 4
  • 38
  • 51