<p>We're using Tekton as our CI/CD solution and want to replace the value of <code>{{DASHBOARD_HOST}}</code> inside our <code>pipeline-run.yml</code>, which looks like this:</p>
<pre><code>apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  generateName: buildpacks-test-pipeline-run-
spec:
  serviceAccountName: buildpacks-service-account-gitlab # Only needed if you set up authorization
  pipelineRef:
    name: buildpacks-test-pipeline
  workspaces:
    - name: source-workspace
      subPath: source
      persistentVolumeClaim:
        claimName: buildpacks-source-pvc
    - name: cache-workspace
      subPath: cache
      persistentVolumeClaim:
        claimName: buildpacks-source-pvc
    - name: maven-repo-cache
      subPath: maven-repo-cache
      persistentVolumeClaim:
        claimName: buildpacks-source-pvc
  params:
    - name: IMAGE
      value: registry.gitlab.com/jonashackt/microservice-api-spring-boot # This defines the name of output image
    - name: REPO_PATH_ONLY
      value: jonashackt/microservice-api-spring-boot
    - name: SOURCE_REVISION
      value: 3c4131f8566ef157244881bacc474543ef96755d
    - name: DASHBOARD_PORT
      value: 8765
    - name: DASHBOARD_HOST
      value: {{DASHBOARD_HOST}}
</code></pre>
<p>We tried to use the approach with <code>sed</code> described <a href="https://stackoverflow.com/a/48297258/4964553">in this so answer</a>:</p>
<pre><code>DASHBOARD_HOST=http://abd1c6f-123246.eu-central-1.elb.amazonaws.com
sed &quot;s/{{DASHBOARD_HOST}}/$DASHBOARD_HOST/g&quot; pipeline-run.yml | kubectl apply -f -
</code></pre>
<p>but get the following error:</p>
<pre><code>bad flag in substitute command: '/'
</code></pre>
<p>Any idea on how to use <code>sed</code> to substitute the <code>{{DASHBOARD_HOST}}</code> variable?</p>

jonashackt
<p>The variable you want to replace contains slashes - and <code>sed &quot;s/{{DASHBOARD_HOST}}/$DASHBOARD_HOST/g&quot;</code> tells <code>sed</code> to use <code>/</code> as the delimiter. This produces the error.  But <a href="https://stackoverflow.com/a/16790877/4964553">as sed <code>s</code> command can use any character as a delimiter</a>, we could optimize the solution using <code>s#</code> instead of <code>s/</code> like this:</p>
<pre><code>sed &quot;s#{{DASHBOARD_HOST}}#$DASHBOARD_HOST#g&quot; app-deployment.yaml | kubectl apply -f -
</code></pre>
<p>We can also ommit the <code>cat</code> as stated by <a href="https://stackoverflow.com/questions/48296082/how-to-set-dynamic-values-with-kubernetes-yaml-file#comment99057121_54168613">gertvdijk</a> since <code>sed</code> is able to read files on it's own. The variable we want to replace inside the <code>app-deployment.yaml</code> could look somehow like this:</p>
<pre><code>...
params:
  - name: DASHBOARD_HOST
    value: {{DASHBOARD_HOST}}
...
</code></pre>
<h2>Multiple variable substitution</h2>
<p>Using sed you can <a href="https://www.gnu.org/software/sed/manual/html_node/Multiple-commands-syntax.html" rel="nofollow noreferrer">even replace multiple variables</a> in your yaml file. Let's assume your <code>app-deployment.yaml</code> has the following contents:</p>
<pre><code>...
params:
  - name: DASHBOARD_HOST
    value: {{DASHBOARD_HOST}}
  - name: DASHBOARD_PORT
    value: {{DASHBOARD_PORT}}
...
</code></pre>
<p>Now set both variables inside your shell:</p>
<pre><code>DASHBOARD_HOST=http://abd1c6f-123246.eu-central-1.elb.amazonaws.com
DASHBOARD_PORT=9785
</code></pre>
<p>And then <a href="https://www.gnu.org/software/sed/manual/html_node/Multiple-commands-syntax.html" rel="nofollow noreferrer">chain the sed <code>s#</code> commands</a> using <code>;</code> like this:</p>
<pre><code>sed &quot;s#{{DASHBOARD_HOST}}#$DASHBOARD_HOST#g;s#{{DASHBOARD_PORT}}#$DASHBOARD_PORT#g&quot; app-deployment.yaml | kubectl apply -f -
</code></pre>
