Closed shumbo closed 3 years ago
@shumbo Can you please open a issue for this PR ?
@shumbo Thanks a lot for working on this. Can you please check if the DRONE_
variables are properly transferred to the GIT_
variables. Looks like environment variables cannot be expanded in the environment
section.
See here. I created an example workflow to double check,
kind: pipeline
name: default
steps:
- name: docker-tag-demo
image: debian:stable-slim
environment:
GIT_BRANCH: ${DRONE_BRANCH}
commands:
- echo "The current branch is ${GIT_BRANCH}"
- echo "The current branch is ${DRONE_BRANCH}"
- echo "The current commit hash is ${DRONE_COMMIT_SHA}"
- echo "The image tag is ${DRONE_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}"
You can put this workflow in a directory, commit it, and run this using
drone exec --branch master --sha <the commit sha>
You would see the GIT_BRANCH
echo in the first command is blank. I think a quick solution to this will be intelligently adding manual commands like
export GIT_BRANCH=$DRONE_BRANCH
to inject the runtime environment variables supported by Popper. Let me know your thoughts.
@JayjeetAtGithub Thanks for your comment.
${VARIABLE}
(dollar sign followed by curly braces) is a Drone's syntax to substitute variables available in Drone before running workflows, whereas $VARIABLE
is variable expansion handled by the shell.
https://docs.drone.io/pipeline/environment/substitution/
In your example, - echo "The current branch is ${GIT_BRANCH}"
should be - echo "The current branch is $GIT_BRANCH"
because GIT_BRANCH
is an environment variable.
kind: pipeline
name: default
type: docker
steps:
- name: docker-tag-demo
image: debian:stable-slim
environment:
GIT_BRANCH: ${DRONE_BRANCH}
commands:
- echo "The current branch is $GIT_BRANCH"
This should print the name of the branch correctly with drone exec --branch master
.
Thanks a lot @shumbo . That works.
Everything seems to work great !
Overview
This PR adds support for environment variable options in Popper-to-Drone translator.
env
optionsPopper has the
env
option to set environment variables in the workflow. You can placeenv
understeps
to define variables for a step, or you can placeenv
underoptions
to define variables throughout the steps.Drone has a similar feature
environment
and has almost identical syntax for defining environment variables. However, it only supports per-pipeline variables (equivalent ofoptions.env
) in Docker pipelines.Hence, I made a decision to inject global variables in each step.
GIT_
VariablesPopper injects multiple variables that represent the status of the git repository. The translator automatically generates definitions of such environment variables in Drone so that scripts written for Popper can continue to work.
The following is the list of variables supported by Popper and corresponding Drone template variables.
GIT_COMMIT
${DRONE_COMMIT_SHA}
GIT_BRANCH
${DRONE_COMMIT_BRANCH}
GIT_SHA_SHORT
${DRONE_COMMIT_SHA:0:7}
GIT_REMOTE_ORIGIN_URL
${DRONE_GIT_HTTP_URL}
GIT_TAG
${DRONE_TAG}
The translator automatically generates bindings and injects them into the output.