<p>As simple it can sounds I am just trying to append these 2 commands below as arguments in my pod during run time. I tested those 2 commands by going inside the pod and running them manually and it worked like a charm. I am just trying to inject those commands inside the cronjob yaml and been scratching my head. Haven't found the right way.</p>
<p><strong>Command 1</strong></p>
<pre><code>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;$PASSWORD\&quot;,\&quot;deviceId\&quot;:\&quot;$UUID\&quot;}&quot; https://$CONTROLLER_IP:444/admin/login --insecure | jq -r '.token'`
</code></pre>
<p><strong>Command 2</strong></p>
<pre><code>curl -k -H &quot;Content-Type: application/json&quot; \
        -H &quot;$API_VS_HD&quot; \
        -H &quot;Authorization: Bearer $TOKEN&quot; \
        -X GET \
        https://$CONTROLLER_IP:444/admin/license/users
</code></pre>
<p>My final current cronjob.yaml file</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: device-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: device-cron-pod
            image: harbor/ops5/private/:device-purge
            command: [&quot;/bin/sh&quot;, &quot;-c&quot;]
            args:
             - export TOKEN=&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;$PASSWORD\\\&quot;,\\\&quot;deviceId\\\&quot;:\\\&quot;$UUID\\\&quot;}\&quot; https://$CONTROLLER_IP:444/admin/login --insecure | jq -r '.token'&quot;;
             - command 2; # should be the curl command
            env:
            - name: AWS_REGION
              value: &quot;us-east-1&quot;
            - name: API_VS_HD
              value: &quot;Accept:application/vnd.appgate.peer-v13+json&quot;
            - name: CONTROLLER_IP
              value: &quot;52.##.###.###&quot;
            - name: UUID
              value: &quot;d2b78ec2-####-###-###-#########&quot;
            - name: PASSWORD
              valueFrom:
                secretKeyRef: 
                  name: password
                  key: password
            imagePullPolicy: Always
          restartPolicy: OnFailure
      backoffLimit: 3
</code></pre>
<p>The current error without appending my second command:</p>
<pre><code>error: error validating &quot;cronjob.yaml&quot;: error validating data: ValidationError(CronJob.spec.jobTemplate.spec.template.spec.containers[0].args[0]): invalid type for io.k8s.api.core.v1.Container.args: got &quot;map&quot;, expected &quot;string&quot;; if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>

kddiji
<p>You can use something like <a href="https://yaml-multiline.info/" rel="nofollow noreferrer">YAML multiline block scalars</a></p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: device-cron-job
  namespace: default
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: device-cron-pod
            image: harbor/ops5/private/:device-purge
            command: 
             - &quot;/bin/sh&quot;
             - -c
             - |
               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;$PASSWORD\&quot;,\&quot;deviceId\&quot;:\&quot;$UUID\&quot;}&quot; https://$CONTROLLER_IP:444/admin/login --insecure | jq -r '.token'`
               curl -k -H &quot;Content-Type: application/json&quot; \
               -H &quot;$API_VS_HD&quot; \
               -H &quot;Authorization: Bearer $TOKEN&quot; \
               -X GET \
               https://$CONTROLLER_IP:444/admin/license/users
            env:
            - name: AWS_REGION
              value: &quot;us-east-1&quot;
            - name: API_VS_HD
              value: &quot;Accept:application/vnd.appgate.peer-v13+json&quot;
            - name: CONTROLLER_IP
              value: &quot;52.##.###.###&quot;
            - name: UUID
              value: &quot;d2b78ec2-####-###-###-#########&quot;
            - name: PASSWORD
              valueFrom:
                secretKeyRef: 
                  name: password
                  key: password
            imagePullPolicy: Always
          restartPolicy: OnFailure
      backoffLimit: 3
</code></pre>
<p>Otherwise the expectation is</p>
<pre><code>command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
args: [&quot;command 1; command 2&quot;]
</code></pre>
<p>instead of</p>
<pre><code>command: [&quot;/bin/sh&quot;, &quot;-c&quot;]
args:
- command 1
- command 2
</code></pre>
<p>hence kubernetes throwing the error <code>invalid type for io.k8s.api.core.v1.Container.args: got &quot;map&quot;, expected &quot;string&quot;;</code></p>
