<p>I set the following github action job to automatically deploy a &quot;nginx&quot; app on EKS and create a &quot;nginx-service&quot; service on push.</p>
<p>I'm trying to configure a skip in the service creation step when the service already exists.</p>
<p>My job:</p>
<pre><code>name: CD_EKS

on:
  - push

jobs:
  eks_nginx_deployment_service:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: eu-central-1

      - name: Trigger deploy
        uses: Consensys/kubernetes-action@master
        env:
          KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
        with:
          args: apply -f nginx_deployment.yaml

      - name: Get Service List
        id: get_service_list
        uses: Consensys/kubernetes-action@master
        env:
          KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
        with:
          args: get services/nginx-service -o name

      - name: Create ELB service
        if: &lt;service doesn't exist&gt; # &lt;- that's my point
        uses: Consensys/kubernetes-action@master
        env:
          KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
        with:
          args: create -f nginx_loadbalancer.yaml
</code></pre>
<p>I tried to refer to the previous step (get_Service_list) output, unsuccessfully.</p>
<p>Thank you</p>

ApprenticeCTO
<p>If you want to skip a step based off of the output of a previous step, try out the following:</p>
<h2>Step 1 - Determine the name of the output you want to use</h2>
<p>If you want to access the output of the <code>ConsenSys/kubernetes-action</code>, we first need to determine what the output's name is. Thankfully, ConsenSys documents this output via the YAML definition of the Action:</p>
<p><em><a href="https://github.com/ConsenSys/kubernetes-action/blob/master/action.yml#L11" rel="nofollow noreferrer">./.action.yml</a></em></p>
<pre class="lang-yaml prettyprint-override"><code>outputs:
  result:
    description: &quot;Output of the kubectl command run&quot;
</code></pre>
<p>To access the output of a step, GitHub Actions support the following expression: <code>${{ steps.STEP_ID.outputs.OUTPUT_NAME }}</code></p>
<p>Since we know the ID of the step you want to use, and ConsenSys documents this Action's output, we then know the final expression is as follows: <code>${{ steps.get_service_list.outputs.result }}</code></p>
<h2>Step 2 - Determine appropriate 'if' statement</h2>
<p>From Step 1, we were able to determine that the output of <code>get_service_list</code> is the output of the kubectl command. This means that one will have to have a little knowledge about kubectl (experimenting locally can help with this). Since you are passing <code>get services/nginx-service -o name</code>, I am assuming that you are checking for the existence of an item named <code>services/nginx-service</code>. If it exists, <code>kubectl get services/nginx-service -o name</code> will output <code>services/nginx-service</code>. If it doesn't exist, kubectl will return an error. In other words, we can say that <em>if the output does <strong>not equal</strong> &quot;services/nginx-service&quot;, run the step named &quot;Create ELB service&quot;</em>.</p>
<h2>Step 3 - Putting it all together</h2>
<p>The above two steps gave us:</p>
<ul>
<li>The proper name of the <code>get_service_list</code> step's output</li>
<li>The conditional we want to use for the step named &quot;Create ELB service&quot;</li>
</ul>
<p>Putting those pieces of information together, the &quot;Create ELB service&quot; step could take on the following form:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: Create ELB service
  if: steps.get_service_list.outputs.result != 'services/nginx-service'
  uses: Consensys/kubernetes-action@master
  env:
    KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
  with:
    args: create -f nginx_loadbalancer.yaml
</code></pre>
<p><strong>note</strong> GitHub Actions automatically assumes that the value of a conditional <code>if</code> keyword is an expression, so you do not have to surround the expression in <code>${{ }}</code>.</p>
<h2>Helpful Links/Notes</h2>
<ul>
<li><a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#operators" rel="nofollow noreferrer">Supported Operators in GitHub Action Expressions</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions" rel="nofollow noreferrer">About contexts and expressions</a></li>
</ul>
