woodpecker-ci / woodpecker

Woodpecker is a simple, yet powerful CI/CD engine with great extensibility.
https://woodpecker-ci.org
Apache License 2.0
4.07k stars 353 forks source link

DRONE_BUILD_STATUS environment variable not set to CI_BUILD_STATUS (makes plugin drillster/drone-email fail) #1416

Closed smainz closed 1 year ago

smainz commented 1 year ago

Component

server, agent

Describe the bug

While trying to port some pipelines from drone to woodpecker-ci I found out, that the drillster/drone-email plugin is not working with woodpecker-ci.

Even if the build is successful, the plugin will always send failure notifications. The reason is, that the plugin checks for DRONE_BUILD_STATUS=='success' (DRONE_BUILD_STATUS is put into the context of a template as build.status, the templates uses this to create the message / subject).

The reason seems is that DRONE_BUILD_STATUS has the value pending. In the docs it says:

NAME Description
CI_BUILD_STATUS build status (success, failure)

DRONE_* environment variables are not mentioned.

A simple env | sort reveals:

CI_BUILD_STATUS=success
CI_JOB_STATUS=success
CI_PIPELINE_STATUS=success
CI_STEP_STATUS=success
DRONE_BUILD_STATUS=pending

Is it intended behavior that CI_BUILD_STATUS differs from DRONE_BUILD_STATUS or a bug?

If the DRONE_* environment variables are just a deprecated legacy, i can offer to fork the plugin and use the correct environment variable. For this it would be helpful, if someone explained to me the difference between BUILD_STATUS, JOB_STATUS, PIPELINE_STATUS and STEP_STATUS and when they are set.

System Info

I am using a simple docker-compose config with

-compose.yml
services:
  woodpecker-server:
    image: woodpeckerci/woodpecker-server:next

...

  woodpecker-agent1:
    image: woodpeckerci/woodpecker-agent:next

Additional context

No response

Validations

smainz commented 1 year ago

Any hint where to start to fix this? metadata.go copies the value, but maybe before the status is set to success / failure.

6543 commented 1 year ago

It's in the drone compatibilety file ...

6543 commented 1 year ago

I guess it's a regression of some refactor

-> https://github.com/woodpecker-ci/woodpecker/pull/1284 would likely fix it ... to, ...

6543 commented 1 year ago

uh now ... that one is set by the agent again

agent/runner.go 293: state.Pipeline.Step.Environment["CI_PIPELINE_STATUS"] = "success" 312: state.Pipeline.Step.Environment["CI_PIPELINE_STATUS"] = "failure"

smainz commented 1 year ago

Do you want me to start fixing it?

6543 commented 1 year ago

sure if you d'like to, go on :)

smainz commented 1 year ago

Hope it is not beyond my current skill level, but shouldn't it be enough to move the call to the drone_compatibility before each call to Runner.run() where the step status is updated? No need to have these env vars in the metadata (is it is only for compatibility with drone plugins).

https://github.com/woodpecker-ci/woodpecker/blob/d785d0571896c89e65c3fc41144b49fac78f2324/agent/runner.go#L309-L319

just copy the env vars before the

return nil