Really simple ask - Is it possible to set Environment Variables within a Pipeline step? Alternatively, is there a way I can accomplish the below use case?
I have a pipeline that gathers some data about changed files within a pipeline, and passes some resulting value to Ansible, which then goes and does some deployment stuff. The second half is the sticking point. I currently use the “filesystem txt file” variables approach, where containers write to the filesystem volume that is shared across all steps.
I’d like to simply SSH to the Ansible server and run a single ansible-playbook command with -e var=somevar environment variable that was from the earlier steps in the pipeline.
The appleboy/drone-ssh plugin only takes environment variables that it can pass to the SSH session - so I can’t pass the resulting .txt file contents to the destination server.
I’ve seen the drone-ansible plugin, but I’m not sure how I can simply have it use the destination Ansible server’s configuration (that I’d have to configure all the specifics ahead of time instead of just “use the destination config”). It also appears that it has the same restriction as drone-ssh, as it only takes environment vars rather than the “vars as filesystem txt” volume option.
The Ansible server is already fully configured with vault, credentials, inventory, etc. all I need to do is run the one ansible-deploy command, assuming I can get that one variable to be passed as well.
Is there then any way to make my use case work? The “standard” is to use filesystem volumes to store data that is then passed to another step. However the next step (drone-ansible or drone-ssh) can’t consume that filesystem data to be used as part if its step, as far as I can tell.
Do I have to go fully manual (script, shell, etc) that does what I am looking for?
I was going to post asking the same question. This is needed in order to utilize the plugins thoroughly. We have a step that calculates semver and then writes that to a file for use with the docker plugin. I would also like to use this with the slack and other plugins though and those only read from env variables. Without it I’m going to have to manually run all the plugins or wrap them.
Correct, under the hood, both steps are sibling processes and it is not possible for a process to modify the variables of its sibling. This is especially true when using containers. At this time, the only way to share data between steps is by writing to disk. Write the data to disk in one step, and read the data from disk in the next step.
Slack supports generating message contents from a template file on disk. You could have a step that generates the template file with the exact message body or title you want to send, so that it could be read by a subsequent slack step.
I suspect most plugins provide some way to customize inputs that are highly probable of being dynamic, but it may not always be obvious. But you are correct, Drone has no formal option for passing variables between steps. This capability is not something we are currently working on, however, it is part of the Harness CI Enterprise offering. See https://harness.io/products/continuous-integration/
We encourage sending pull requests to improve documentation. You can also provide actionable feedback for documentation improvements here in discourse. We also have a dedicated section in our forum to share actionable documentation feedback.