Promote target is copied from a previous promote

We have a pipeline that can be promoted to a few different envs/targets. If a build is promoted to 2 envs one by one, context.build.environment value is the same on each promote.

Steps to reproduce:

  1. Create the following buildspec:
def main(ctx):
    return [
        promote_pipeline(ctx),
        test_pipeline(),
    ]

def promote_pipeline(ctx):
    env = ctx.build.environment

    return {
        'kind': 'pipeline',
        'name': 'promote/rollback build pipeline',
        'steps': [
            {
                'name': 'name env we are promoting to',
                'image': 'alpine',
                'commands': [
                    'echo "promoting {}"'.format(env),
                ],
            }
        ],
        'trigger': {
            'event': ['promote'],
            'target': [
                'staging',
                'uat',
                'prod',
            ]
        }
    }

def test_pipeline():
    return {
        'kind': 'pipeline',
        'name': 'testing pipeline',
        'steps': [
            {
                'name': 'say hello',
                'image': 'alpine',
                'commands': [
                    'echo "HELLO WORLD!"',
                ],
            }
        ],
        'trigger': {
            'branch': ['master']
        }
    }
  1. Promote the build from step 1 to uat
  2. Promote the build from step 1 to prod

Expected result:

  1. promote/rollback build pipeline output: promoting uat
  2. promote/rollback build pipeline output: promoting prod

Actual result:

  1. promote/rollback build pipeline output: promoting uat
  2. promote/rollback build pipeline output: promoting uat

For some reason Drone preserves context.build.environment value from previous promote event. Can be fixed by a drone-server container restart.

Are you using the external Starlark extension? When Drone makes API calls to external extensions it caches the resulting yaml based on commit sha, branch and event type. You are likely receiving the cached result.

Instead of using the external Starlark extension (which is subject to caching) perhaps consider using the embedded Starlark interpreter. As an added bonus this would simplify your installation. The embedded Starlark interpreter is available in Drone server version 1.10.0 and higher and can be enabled by passing the following settings to your server:

DRONE_STARLARK_ENABLED=true

Note that when you enable the embedded Starlark interpreter you should remove the Starlark conversion extension from your configuration.

Looks like the embedded interpreter does not support external loads/imports feature that is critical for us (https://github.com/drone/drone/blob/master/plugin/converter/starlark/starlark.go#L53-L54) unlike the starlark extension (https://github.com/drone/drone-convert-starlark/commit/0a532618c6ee7705964762efe37e380865643a8a). Are you going to implement the load/import support for the embedded interpreter too?