<p>I am trying to deploy a kubernetes cluster using Travis CI and I get the following error</p>
<p>EDIT:</p>
<blockquote>
<p>invalid argument &quot;myAcc/imgName:&quot; for t: invalid reference format</p>
<p>See docker build --help</p>
<p>./deploy.sh: line 1: kubectl: command not found</p>
</blockquote>
<p>This is my travis config file</p>
<p><code>travis.yml</code></p>
<pre><code>sudo: required
services: 
  - docker
env:
  global:
    - SHA-$(git rev-parse HEAD)
    - CLOUDSDK_CORE_DISABLE_PROMPTS=1
before-install:
  - openssl aes-256-cbc -K $encrypted_0c35eebf403c_key -iv $encrypted_0c35eebf403c_iv -in service-account.json.enc -out service-account.json -d
  - curl https://sdk.cloud.google.com | bash &gt; /dev/null
  - source $HOME/google-cloud-sdk/path.bash.inc
  - gcloud components update kubectl
  - gcloud auth activate-service-account --key-file service-account.json
  - gcloud config set project robust-chess-234104
  - gcloud config set compute/zone asia-south1-a
  - gcloud container clusters get-credentials standard-cluster-1
  - echo &quot;$DOCKER_PASSWORD&quot; | docker login -u &quot;$DOCKER_USERNAME&quot; --password-stdin

deploy:
  provider: script
  script: bash ./deploy.sh
  on: 
    branch: master
</code></pre>
<p>This is my deploy script</p>
<p><code>deploy.sh</code></p>
<pre><code>doccker build -t myAcc/imgName:$SHA
docker push myAcc/imgName:$SHA
kubectl apply -k8s
</code></pre>
<p>I guess the <code>gcloud components update kubectl</code> command is not working. Any ideas?</p>
<p>Thanks !</p>

<p>The first issue <code>invalid argument "myAcc/imgName:" for t: invalid reference format</code> because the variable <code>$SHA</code> is not defined as expected. There is a syntax issue with defining the variable you should use <code>=</code> instead of <code>-</code> after SHA, so it should be like this:</p>

<pre><code>- SHA=$(git rev-parse HEAD)
</code></pre>

<p>The second issue which is related to kubectl you need to install it using the following command according to the <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#download-as-part-of-the-google-cloud-sdk" rel="nofollow noreferrer">docs</a>:</p>

<pre><code>gcloud components install kubectl
</code></pre>

<p><strong>Update</strong>:</p>

<p>After testing this file on Travis-CI I was able to figure out the issue. You should use <code>before_install</code> instead of <code>before-install</code> so in your case the before installation steps never get executed.</p>

<pre><code># travis.yml
---
env:
  global:
    - CLOUDSDK_CORE_DISABLE_PROMPTS=1
before_install:
 - curl https://sdk.cloud.google.com | bash &gt; /dev/null
 - source $HOME/google-cloud-sdk/path.bash.inc
 - gcloud components install kubectl

script: kubectl version

</code></pre>

<p>And the final part of the build result:</p>

<pre><code>$ kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.7", GitCommit:"65ecaf0671341311ce6aea0edab46ee69f65d59e", GitTreeState:"clean", BuildDate:"2019-01-24T19:32:00Z", GoVersion:"go1.10.7", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>
