Reputation: 1409
I am completely new to drone CI/CD. I am facing issue on passing environment variables to drone plugin. What i did upto now is
.drone.yml
file to projectcloud.docker.com
app. Now i want to deploy that image to my other cloud server (my.app.com
). So, I added applebody/drone-ssh to drone.yml to access that servermy.app.com
) through ssh.my.app.com
from my.drone.com
servermy.drone.com
private ssh key to plugin through environment varibles. But didn't workout. my drone's server and agent env file and .drone.yml
as follows:.drone.yml
pipeline:
ssh:
image: appleboy/drone-ssh
host: my.app.com
user: root
key: $PLUGIN_SSH_KEY
script:
- ls
- cd apps
- docker pull drprasad/todo-app
- docker rm -f todo
- docker run -p 8080:8080 -d --name 'todo' drprasad/todo-app
notify:
image: plugins/slack
webhook: https://hooks.slack.com/services/token
channel: test
username: drone-is-flying
agent env file
DRONE_SECRET=my_drone_secret_key
DRONE_SERVER=ws://drone-server:8000/ws/broker
PLUGIN_SSH_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAzMW5gU9I071UdnBDANbvuprd+1QwBEXWUq0gvi44ECUDZhzL
...............................................................
...............................................................
-----END RSA PRIVATE KEY-----"
server env
DRONE_SECRET=my_drone_secret_key
DRONE_HOST=my.drone.com:8082
DRONE_OPEN=true
DRONE_BITBUCKET=true
DRONE_BITBUCKET_CLIENT=my_bitbucket_client_token
DRONE_BITBUCKET_SECRET=my_bitbucket_secret_key
PLUGIN_SSH_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAzMW5gU9I071UdnBDANbvuprd+1QwBEXWUq0gvi44ECUDZhzL
...............................................................
...............................................................
-----END RSA PRIVATE KEY-----"
How can pass PLUGIN_SSH_KEY
variable (either from agent or server env file) to drone plugin ?? so that it can access my my.app.com
server
Even I dont know my approach is correct or not. Please correct me if my approach is wrong.
Sorry for my bad english. Thanks
Upvotes: 1
Views: 7489
Reputation: 2563
This is not supported syntax. The key
value in your example is a Go string literal and therefore cannot evaluate a bash expression.
key: $PLUGIN_SSH_KEY
If you want to pass sensitive parameters (such as keys) to your build you can do so using the drone secret store [1]. You can upload secrets using the command line utility or in the user interface.
You can then pass those secrets to the plugin. Please see the official documentation [1] for a more in-depth explanation. Here is a brief example of how the syntax should look:
pipeline:
image: appleboy/drone-ssh
host: my.app.com
user: root
secrets: [ SSH_KEY ]
Note that the plugin expects the secret to be named SSH_KEY. The official documentation [1] describes what to do if the secret has a different name.
Further reading:
[1] http://docs.drone.io/manage-secrets/
[2] Drone CI does not see secret variables when using drone-email plugin
Upvotes: 2