0.7.3 - fork build with parameters

Following the thread in Trigger downstream and the implementation in drone-downstream, I want to start a new build with a specific parameter. I start by getting the latest build available for the branch.

BUILD=$(curl  -sH "Authorization: Bearer ${SERVICE_TOKEN}" 'https://{server}/api/repos/{owner}/{repo}/builds/latest?branch={branch}' | jq .number)

And start a new forked build with my parameter.

curl -s -X POST -H "Authorization: Bearer ${SERVICE_TOKEN}" "https://{server}/api/repos/{owner}/{repo}/builds/$BUILD?IMAGE_TAG=deadbeef&fork=true"

I get a new build, but the parameter isn’t available in the pipeline either specified in the environment or within the commands:

  build:
    image: myimage
    environment:
      - IMAGE_TAG=${IMAGE_TAG} # tried specifying here
    commands:
      - echo ${IMAGE_TAG} # this is always blank
      - IMAGE_TAG=${IMAGE_TAG} # also tried specifying here without the environment declaration and above command
      - echo $IMAGE_TAG # this is always blank

Can someone point me in the right direction to get this working? Thanks!

I can offer a more complete example:

pipeline:
  param_test:
    image: busybox
    environment:
      - ENV_PARAM=${PARAM1=undefined}
      - CONST_PARAM=yes
    commands:
      - echo CONST_PARAM=$CONST_PARAM
      - echo ENV_PARAM=$ENV_PARAM
      - CMD_PARAM=${PARAM2=undefined}
      - echo CMD_PARAM=$CMD_PARAM

Using the following command:

curl -s -X POST -H "Authorization: Bearer ${SERVICE_TOKEN}" "https://{server}/api/repos/{owner}/{repo}/builds/2?PARAM1=please&PARAM2=work&fork=true"

I get the following output on the triggered build:

+ echo CONST_PARAM=$CONST_PARAM
CONST_PARAM=yes
+ echo ENV_PARAM=$ENV_PARAM
ENV_PARAM=undefined
+ CMD_PARAM=undefined
+ echo CMD_PARAM=$CMD_PARAM
CMD_PARAM=undefined

while running locally with PARAM1=please PARAM2=work drone exec I get:

+ echo CONST_PARAM=$CONST_PARAM
CONST_PARAM=yes
+ echo ENV_PARAM=$ENV_PARAM
ENV_PARAM=please
+ CMD_PARAM=work
+ echo CMD_PARAM=$CMD_PARAM
CMD_PARAM=work

There was a regression in 0.7, which was fixed in 0.8

Relevant patch c95d2bf9f024f3361063b2bb1ad82ecb53c6ebc2

1 Like

I spun up Drone 0.8.1, and am experiencing the same issue with parameters not being available in the environment of the triggered build. Any further help and ideas would be very much appreciated!

If I understand correctly you are trying to interpolate custom build variables in the yaml. These values are passed to your container as environment variables, but cannot be interpolated in the yaml.

If we look at your example …

environment:
  ENV_PARAM=${PARAM1=undefined}

The above line would not work because PARAM1 is not available to the yaml pre-process for substitution. It is also unnecessary because PARAM1 is already available to your container as an environment variable.

The practice of interpolating environment variables in the environment section was required for older versions of drone (pre 0.6) but is no longer required since these variables are already available to your environment.

1 Like

I also wanted to provide some additional detail. I ran a quick test to confirm custom parameters are being passed to the pipeline as environment variables. I ran the following command to trigger a build:

drone build start -p AN_EXAMPLE_PARAM=hello bradrydzewski/foobar 597

I added a command to the yaml to dump available environment variables:

pipeline:
  test:
    image: golang
    commands:
      - env

I then confirmed the environment variable was displayed in the build logs:

1 Like

Yes, thank you! I see that I didn’t understand that the build parameters were available directly as environment variables, instead of being available as part of the interpolation. Thanks for clearing that up!

Appears this is working in 0.7.3 as well, for the record. Thanks!