<p>Basically I'm trying to create a pipeline on my local Jenkins, create an image and then send to Docker Hub. Then I'll deploy this image on our local Kubernetes(Server IP:10.10.10.4).</p>
<p>So Jenkins pipeline script is below;</p>
<pre><code>docker build -t test123/demo:$BUILD_NUMBER . 
docker login --username=testuser --password=testpass
docker push test123/demo:$BUILD_NUMBER
ssh -tt root@10.10.10.4 'kubectl apply -f hybris-deployment.yaml'
</code></pre>
<p>So the problem is; I can tag succesfully images with $BUILD_NUMBER and push to Docker hub. Then I have to use this $BUILD_NUMBER in the Kubernetes server's YAML file and deploy it.</p>
<p>But I can't pass this $BUILD_NUMBER to the Kubernetes server. Somehow I should send this build number with the ssh command and use it in the YAML file as a tag.</p>
<p>Any idea how can I do that?
Thanks!</p>

yatta
<p>you create your pipeline something like</p>
<p>if you <strong>deployment.yaml</strong> file is like</p>
<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: test-image
  labels:
    app: test-image
spec:
  selector:
    matchLabels:
      app: test-image
      tier: frontend
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: test-image
        tier: frontend
    spec:
      containers:
      - image: TEST_IMAGE_NAME
        name: test-image
        ports:
        - containerPort: 8080
          name: http
        - containerPort: 443
          name: https
</code></pre>
<p>in pipeline, you can change the image and replace this part in <strong>deployment.yaml</strong></p>
<pre><code>sed -i &quot;s,TEST_IMAGE_NAME,gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA,&quot; deployment.yaml
</code></pre>
<p>so this command will replace line, in <strong>deployment.yaml</strong> and this way image URL updated and you can apply the YAML file.</p>
<p>you can see the example jenkin file here : <a href="https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes/blob/master/sample-app/Jenkinsfile" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes/blob/master/sample-app/Jenkinsfile</a></p>
<p>whole project link : <a href="https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes</a></p>
