<p>I am running a Kubernetes CronJon with a HTTPS GET using curl command. Token has to be retrieved before any POST or GET commands.
Setting these env var locally in my <code>.bashrc</code> file and running the curl command works fine when I test locally.</p>
<pre class="lang-sh prettyprint-override"><code># ~/.bashrc: executed by bash(1) for non-login shells.
export api_vs_hd=Accept:application/vnd.appgate.peer-v13+json
export controller_ip=value
export admin_pass=value
export uuid=value
export token=`curl -H &quot;Content-Type: application/json&quot; -H &quot;${api_vs_hd}&quot; --request POST --data &quot;{\&quot;providerName\&quot;:\&quot;local\&quot;,\&quot;username\&quot;:\&quot;admin\&quot;,\&quot;password\&quot;:\&quot;$admin_pass\&quot;,\&quot;deviceId\&quot;:\&quot;$uuid\&quot;}&quot; https://$controller_ip:444/admin/login --insecure | jq -r '.token'`
</code></pre>
<pre class="lang-sh prettyprint-override"><code>$ curl -k -H &quot;Content-Type: application/json&quot; \
&gt;      -H &quot;$api_vs_hd&quot; \
&gt;      -H &quot;Authorization: Bearer $token&quot; \
&gt;      -X GET \
&gt;      https://$controller_ip:444/admin/license/users
{&quot;data&quot;:[],&quot;range&quot;:&quot;0-0/0&quot;,&quot;orderBy&quot;:&quot;created&quot;,&quot;descending&quot;:true,&quot;filterBy&quot;:[]}
</code></pre>
<p>However, I am getting a parsing error when linting this YAML and I am sure it's due to the format on my value in the <code>TOKEN</code> key: <code>curl ...</code> command.
See CronJob YAML</p>
<pre class="lang-yaml prettyprint-override"><code>#file-name: postgresql-backup-cron-job.yaml

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cron-job
  namespace: device-purge
spec:
#Cron Time is set according to server time, ensure server time zone and set accordingly.
  schedule: &quot;*/2 * * * *&quot; # test
  jobTemplate:
    spec:
      template:
        spec:
          imagePullSecrets:
          - name: cron
          containers:
          - name: cron-pod
            image: harbor/privateop9/python38:device-purge
            env:
            - name: API_VS_HD
              value: &quot;Accept:application/vnd.appgate.peer-v13+json&quot;
            - name: CONTROLLER_IP
              value: &quot;value&quot;
            - name: ADMIN_PASS
              value: &quot;value&quot;
            - name: UUID
              value: &quot;value&quot;
            - name: TOKEN
              value: &quot;curl -H \&quot;Content-Type: application/json\&quot; -H \&quot;${api_vs_hd}\&quot; --request POST --data \&quot;{\&quot;providerName\&quot;:\&quot;local\&quot;,\&quot;username\&quot;:\&quot;admin\&quot;,\&quot;password\&quot;:\&quot;$admin_pass\&quot;,\&quot;deviceId\&quot;:\&quot;$uuid\&quot;}&quot; https://$controller_ip:444/admin/login --insecure | jq -r '.token'&quot;
            imagePullPolicy: Always
          restartPolicy: OnFailure
      backoffLimit: 3
</code></pre>

kddiji
<p>You forgot to escape one double quote here:</p>
<pre><code>... \&quot;deviceId\&quot;:\&quot;$uuid\&quot;}&quot; https:/ ...
                           ^
</code></pre>
<p>Escaping this will fix the YAML. However, the value will not be correct because as you can see, your original command already needs escape sequences for the double quotes inside <code>data</code> so you would need to <em>escape the escape sequences</em>, like <code>\\\&quot;</code> for every sequence.</p>
<p>A vastly simpler way to enter the command would be a folded block scalar:</p>
<pre class="lang-yaml prettyprint-override"><code>            - name: TOKEN
              value: &gt;-
                curl -H &quot;Content-Type: application/json&quot; -H &quot;${api_vs_hd}&quot; --request POST
                --data &quot;{\&quot;providerName\&quot;:\&quot;local\&quot;,\&quot;username\&quot;:\&quot;admin\&quot;,\&quot;password\&quot;:\&quot;$admin_pass\&quot;,\&quot;deviceId\&quot;:\&quot;$uuid\&quot;}&quot;
                https://$controller_ip:444/admin/login --insecure | jq -r '.token'
</code></pre>
<p>In a folded block scalar, no escape sequences are processed so you can give the original command.
Also, line breaks will be folded into single spaces so you can enter your command on multiple lines for readability.
Just make sure that you do not indent lines more than the first line, YAML has a <em>really weird</em> special case for that where it <em>doesn't</em> remove newlines around more-indented lines.</p>
