-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: A way to pass variables between task steps. #1476
Comments
There isn't a way to export environment variables from one step into another. A different possible approach would be to use files on disk for a similar purpose. All steps in a Task share a workspace volume. This allows the following: apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: example-task-name
spec:
inputs:
resources:
- name: workspace
type: git
params:
- name: pathToDockerFile
type: string
description: The path to the dockerfile to build
default: /workspace/workspace/Dockerfile
outputs:
resources:
- name: builtImage
type: image
steps:
- name: write-to-workspace
image: ubuntu
script: |
#!/usr/bin/env bash
echo "bar" > /workspace/FOO
- name: read-from-workspace
image: ubuntu
script: |
#!/usr/bin/env bash
export FOO=$(cat /workspace/FOO)
echo $FOO (I'm using the |
This is similar to #1273. However, inter- |
Not a solution but an interesting approach to a similar problem: @afrittoli added an init container for our dogfood cron pods that writes a script to a known location that initializes environment variables: |
Cool, thanks. Yeah I didn't want to have to do the shared volume mount + cat thing, but I guess if need be, I'll use that technique. The example above is great. Maybe this shared volume with the exports can be built into to the underlaying task CRDs? Sounds like a useful feature. |
We're working on a feature called workspaces that will eventually expose / override the shared volume stuff as part of the tekton CRDs. The WIP PR is up at #1639 We're also designing / working on the output params feature described in #1273 as @vtereso mentioned. I haven't heard any strong dissents against that feature and it sounds to me at the moment like there is some support in the community for it. Hopefully only a matter of time until it's implemented 🤞. Given that the original question has been answered I'm going to close out this thread in favor of ongoing discussion on the above issues. |
Is there a way set an env variable in one task step and then have the subsequent task step be able to read that in or interpolate it in an arg? Admittedly, I don't fully understand if env variables are shared between multiple images / steps in the same task.
What I want to do is have a little script in one task step read a file and set env variables, so that the subsequent task step (kaniko) can get things dynamically from env variables set in the container, rather than passed in as params to the task run eg. I won't know the name of Dockerfile or path to context until I read the file from git source.
Here's my question on SO, which also appears to be the first Tekton tag 🎉 .
Very cool stuff, thanks!
https://stackoverflow.com/questions/58561514/pass-env-vars-from-one-tekton-task-step-to-the-next
rough example of what I want to do.
The text was updated successfully, but these errors were encountered: