# \[Solved\] Set variables to plugin params?

**URL:** <https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942>\
**Category:** Drone Support\
**Created:** [March 23, 2018, 7:05am UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942 "2018-03-23T07:05:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 7:05am UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/1 "2018-03-23T07:05:42Z")

</div>

Hello i have successfully setup and integrated one of my projects with drone… its amazing… however i found one issue that might be the key factor if i will be able to keep using this CI along with my other projects…

```
  deploy:
    image: appleboy/drone-scp
    host: example.com
    target: /home/ec2-user/public/
    secrets: [ssh_username, ssh_key]
    source:
      - dist/**

```

i have several other projects hosted in different servers, which uses different username + different ssh\_keys (which i have no control over) what i am trying to do is have something like this

```
  deploy:
    image: appleboy/drone-scp
    host: $PROJECT_A_HOST
    target: $PROJECT_A_TARGET
    key: $PROJECT_A_KEY
    user: $PROJECT_A_USER
    source:
      - dist/**

```

but according with this resolution of this issue: [drone.io - access environment variables of drone in drone plugins - Stack Overflow](https://stackoverflow.com/questions/46350675/access-environment-variables-of-drone-in-drone-plugins?noredirect=1&lq=1)

GO can not evaluate bash expressions… is there a work around for this kind of situation?

---

<div class="post-metadata">

**Author:** ![gboddin](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/gboddin/32/3701_2.png) [@gboddin](https://drone.discourse.group/u/gboddin)\
**Post date:** [March 23, 2018, 8:29am UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/2 "2018-03-23T08:29:19Z")

</div>

@milewski not sure I totally get your question but :

I would advice to check the documentation on subsitution : [http://docs.drone.io/substitution/](http://docs.drone.io/substitution/)

But ultimately I think you’re looking for secret mapping :

Later in the build you can use the followin trick to import variable from secrets into plugin :

```auto
  deploy:
    image: appleboy/drone-scp
    secrets:
      - source: project_a_host
        target: plugin_host
      - source: project_a_target
        target: plugin_target
      - source: project_a_key
        target: key
      - source: project_a_user
        target: user
    source:
      - dist/**

  deploy:
    image: appleboy/drone-scp
    secrets:
      - source: project_b_host
        target: plugin_host
      - source: project_b_target
        target: plugin_target
      - source: project_b_key
        target: key
      - source: project_b_user
        target: user
    source:
      - dist/**

```

PS: prefixing with plugin\_ allows for providing plugin parameters from secrets.

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 10:58am UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/3 "2018-03-23T10:58:07Z")

</div>

> [@On another topic](https://drone.discourse.group/t/1979/2):
>
> PS: prefixing with plugin\_ allows for providing plugin parameters from secrets.

Exactly what i was looking for!!.. i couldn’t find this on the documentation… thanks i will give ie a try

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 3:29pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/4 "2018-03-23T15:29:22Z")

</div>

Well i have just tried… and i get this error:

```auto
missing ssh config (Host, Username)

```

any idea what could be wrong?

```auto
 deploy:
    image: appleboy/drone-scp
    secrets:
      - source: project_b_host
        target: plugin_host
      - source: project_b_target
        target: plugin_target
      - source: project_b_key
        target: plugin_key
      - source: project_b_user
        target: plugin_user // have prefixed this with plugin like the other options
    source:
      - dist/**

```

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [March 23, 2018, 3:40pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/5 "2018-03-23T15:40:21Z")

</div>

do you have the secret `project_b_host` configured as a drone secret variable?

- [http://docs.drone.io/manage-secrets/](http://docs.drone.io/manage-secrets/)
- [http://docs.drone.io/secrets-not-working/](http://docs.drone.io/secrets-not-working/)

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 3:43pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/6 "2018-03-23T15:43:00Z")

</div>

yes, but technically not with that names… here is the real names i am using within my tests

```auto
  deploy:
    image: appleboy/drone-scp
    secrets:
      - source: host
        target: plugin_host
      - source: deployment_path
        target: plugin_target
      - source: private_key
        target: plugin_key
      - source: user
        target: plugin_user
    source:
      - distribution/**

```

maybe the variable name HOST is reserved? or might being overridden by some system variables?

edit. Just changed the names to something else but i still get the same error

---

<div class="post-metadata">

**Author:** ![gboddin](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/gboddin/32/3701_2.png) [@gboddin](https://drone.discourse.group/u/gboddin)\
**Post date:** [March 23, 2018, 4:45pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/7 "2018-03-23T16:45:12Z")

</div>

@milewski

You have to be careful about the target name.

When the target is a real secret, you shouldn’t prefix it with plugin\_

So effectively :

```auto
 deploy:
    image: appleboy/drone-scp
    secrets:
      - source: project_b_host
        target: plugin_host
      - source: project_b_target
        target: plugin_target
      - source: project_b_key
        target: key
      - source: project_b_user
        target: user // SOULDN'T have prefixed this with plugin like the other options
    source:
      - dist/**

```

would work better

also if I’m correct. for the SCP plugin the secret name for user is `username`

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 5:05pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/8 "2018-03-23T17:05:49Z")

</div>

according with the [SCP plugin docs](http://plugins.drone.io/appleboy/drone-scp/) the only options that can be passed from secrets are:

`Secret Reference`

```auto
ssh_username
ssh_password
ssh_key
proxy_ssh_username
proxy_ssh_password
proxy_ssh_key

```

and the other options are listed as `Parameter Reference`

```auto
host
target
user
key

```

i have also tried without the `plugin_` prefix only in the `key` and `user` but got the same error message: `missing ssh config (Host, Username)` which i believe is caused because the HOST is not available as a secret, so back to my original question, what i wanted to do is give the value to this HOST param dynamically.

that’s why i didn’t understand why prefixing `host` with `plugin_` was allowed in your example but not `user` and `key` as all of them are listed as Parameter in the doc…

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 5:21pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/9 "2018-03-23T17:21:22Z")

</div>

> [@On another topic](https://drone.discourse.group/t/1979/7):
>
> When the target is a real secret, you shouldn’t prefix it with plugin\_

Cool thanks! this lead me to the solution.

Following config is working now:

```auto
    secrets:
      - source: project_b_host
        target: plugin_host
      - source: project_b_target
        target: plugin_target
      - source: project_b_key
        target: ssh_key
      - source: project_b_user
        target: ssh_username

```

but still don’t quite understand why `host`, `user` and `key` are listed as params but couldnt work with the `plugin_` prefix, is this something to do with the way this docker image script was build? maybe didn’t take this in consideration? or this parsing and replacing happens on the drone side? and this is potentially a bug? i would like to assume that every “Parameter” could be set dynamically by this secret trick but for some reason i don’t yet understand it didn’t worked out…

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [March 23, 2018, 5:31pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/10 "2018-03-23T17:31:35Z")

</div>

> [@On another topic](https://drone.discourse.group/t/1979/9):
>
> or this parsing and replacing happens on the drone side? and this is potentially a bug

The system is behaving as expected. Aside from passing secret environment variable names as uppercase, drone does not transform or alter the secret environment variable names in any way.

reference code:

```auto
environment[strings.ToUpper(requested.Target)] = secret.Value

```

Please note that secret names **do not** by default correspond to the yaml attribute names. To learn more about how yaml atrributes are passed to the plugin, you might find the following document helpful: [https://docs.drone.io/plugins/tutorials/bash/](http://docs.drone.io/creating-custom-plugins-bash/)

You can reference the plugin [source code](https://github.com/appleboy/drone-scp/blob/master/main.go) to see which environment variables it reads:

```plaintext
		cli.StringFlag{
			Name: "username, u",
			Usage: "Server username",
			EnvVar: "PLUGIN_USERNAME,SCP_USERNAME,SSH_USERNAME",
		},

```

---

<div class="post-metadata">

**Author:** ![milewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/milewski/32/4033_2.png) [@milewski](https://drone.discourse.group/u/milewski)\
**Post date:** [March 23, 2018, 5:51pm UTC](https://drone.discourse.group/t/solved-set-variables-to-plugin-params/9942/11 "2018-03-23T17:51:50Z")

</div>

Thanks! i got how it works now! and thanks for the source code! i can work out on building my own plugins now!
