Drone CI does not see secret variables when using

2019-07-27 12:27发布

问题:

I'm using drone-ci (0.8.0-rc.5) as CI tool and drone-email plugin for sending emails. I would like to send notifications if a build succeeded or failed. I use the Gmail SMTP server for sending emails.

My .drone.yml file:

notify:
  image: drillster/drone-email
  host: ${EMAIL_HOST}
  port: ${EMAIL_PORT}
  username: ${EMAIL_USERNAME}
  password: ${EMAIL_PASSWORD}
  from: test@test.com
  recipients: [ user@test.com ]

Secrets are configured like on the picture below: When the build finishes, I receive following exception:

time="2017-09-20T02:14:10Z" level=error msg="Error while dialing SMTP server: dial tcp :587: getsockopt: connection refused" dial tcp :587: getsockopt: connection refused

When I hardcode values in yml file, notifications work. So I'm wondering what I'm doing wrong with secrets or how to fix this situation?

回答1:

The syntax you are using, ${secret}, was deprecated in drone 0.6 and replaced with the following syntax:

pipeline:
  notify:
    image: drillster/drone-email
    from: test@test.com
    recipients: [ user@test.com ]
    secrets: [EMAIL_HOST, EMAIL_PORT, EMAIL_USERNAME, EMAIL_PASSWORD]

The above syntax instructs drone to provide the requested secrets to the plugin. The secrets are exposed into the container as environment variables and consumed by the plugin.

Further reading

  • http://docs.drone.io/manage-secrets/
  • http://docs.drone.io/secrets-not-working/#variable-expansion
  • http://docs.drone.io/release-0.6.0 (see breaking changes section)