6

So Tekton Pipelines allows you to create individual tasks and connect them into cloud native ci/cd pipelines. It's pretty cool. But as you can imagine, so things you would think are easy, are pretty tricky. For example, I'm trying to run a Kaniko executor as a task, but that executor needs specific arguments. I can hard code those args, but that makes the task less re-usable, so I'd like a previous task to simply read a config file from source and output or set env variables for the subsequent task. Not sure how to do this. In the case of Kaniko, its really tricky because you don't have any shell or anything. Any suggestions?

Here's a sample task from their documentation that I've tweaked to kind of show what I'm trying to do.

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: ubuntu-example
      image: ubuntu
      args: "export FOO=bar"
    - image: gcr.io/example-builders/build-example
      command: ["echo $FOO"]
4m1r
  • 12,234
  • 9
  • 46
  • 58

2 Answers2

2

I tried to achieve the same and found a (hacky) solution: You can make use of the concept of workspaces and write your variable value to a file. You can use this also to mix between different types of scripts (python and sh in this example):

steps:
    - name: python-write-value
      image: python:3.7-alpine
      script: |
        #!/usr/bin/env python3
        value = "my_value_to_share"
        f = open("/workspace/value.txt","w+")
        f.write(value)
    - name: sh-read-value
      image: ubuntu
      script: |
        value=$(cat /workspace/value.txt)
        echo $value
johaaachim
  • 78
  • 2
  • 7
1

There is no easy way to do this for now, but you can use task params and task-results.

Guilherme Torres Castro
  • 15,135
  • 7
  • 59
  • 96