# Rancher 2.x with Gitlab

**URL:** <https://forums.suse.com/t/rancher-2-x-with-gitlab/13508>\
**Category:** SUSE Rancher Prime\
**Created:** [February 28, 2019, 11:36pm UTC](https://forums.suse.com/t/rancher-2-x-with-gitlab/13508 "2019-02-28T23:36:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogo\_Marcelo](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/diogo_marcelo/32/4895_2.png) [@Diogo\_Marcelo](https://forums.suse.com/u/Diogo_Marcelo)\
**Post date:** [February 28, 2019, 11:36pm UTC](https://forums.suse.com/t/rancher-2-x-with-gitlab/13508/1 "2019-02-28T23:36:24Z")

</div>

Hi everyone,

Im getting some trouble with integration of gitlab and rancher.  
Im trying to integrate gitlab k8’s feature, but im getting error when i try to deploy.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/a/a9b7db808d4d26de82593349f192eaa540fa2dbe.png)

All components had been installed correctly (helm, ingress, certmanager…etc) but when i try to run the pipeline and deploy i get the error.  
The namespace was created in rancher with that config.

I need help to understand this problem.

Thanks  
Diogo Marcelo

---

<div class="post-metadata">

**Author:** ![zwordi](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/zwordi/32/4898_2.png) [@zwordi](https://forums.suse.com/u/zwordi)\
**Post date:** [March 1, 2019, 1:38pm UTC](https://forums.suse.com/t/rancher-2-x-with-gitlab/13508/2 "2019-03-01T13:38:08Z")

</div>

Hello Diego,

You are following the AutoDevOps template from Gitlab.

You have to know that you need to put all the necessary variables available for your jobs to succeed like an kubernetes integration per project.

Or you can tweak it a bit to fit your need in a smallest way.

Recently i managed to have an image update on a deployement using another docker image with Rancher\_url et Rancher\_token (for example) in order to first log into the rancher than to run my kubectl command.  
I used this link from [Stackoverflow](https://stackoverflow.com/questions/51139177/upgrade-rancher-2-workload-from-cli/51174128#51174128) as reference than i build two new function on the `gitlab-ci.yml` file named `rancher_connect` and `rancher_update`.

`
function rancher_connect() {
    if [["$RANCHER_API_TOKEN" && "$RANCHER_SERVER_URL" && "$RANCHER_SERVER_CONTEXT"]]; then
      echo "Logging to Rancher with CI credentials..."
      rancher login "$RANCHER_SERVER_URL" -t "$RANCHER_API_TOKEN" --context "$RANCHER_SERVER_CONTEXT"
      echo ""
    else
      echo "Error during login - check that you have variables set on the project level"
    fi
  }
function rancher_update() {
rancher kubectl YOUR STUFF HERE (from a file or full command line)
sleep 15
rancher kubectl YOUR STUFF HERE (from a file or full command line)
}

update_ressources:
stage: deploy
image: diemscott/rancher-cli-k8s:v2.0.2
allow_failure: true
script:
- rancher_connect
- rancher_update
only:
- branches
`  
Remember that it’s only working for my use case you might need to adapt it to yours.

I hope it was helpful and wish you an good week-end.

Zwordi

---

<div class="post-metadata">

**Author:** ![Sergio\_Hume](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sergio_hume/32/5434_2.png) [@Sergio\_Hume](https://forums.suse.com/u/Sergio_Hume)\
**Post date:** [July 31, 2019, 1:56am UTC](https://forums.suse.com/t/rancher-2-x-with-gitlab/13508/3 "2019-07-31T01:56:35Z")

</div>

Hi, that solutions doesn’t work for me, i pass project id in context, like “c-42fm9:p-gdr2q”, if i don’t pass context fail with a message showing me the list of projects…anyone can help me please.

My use case is using this inside a .gitlab-ci.yml, like this:

- rancher login $SERVER --token $TOKEN --context $CONTEXT
  - rancher kubectl apply -f k8s/secret-container-registry.yml
  - rancher kubectl apply -f k8s/ms-deployment.yml

Thanks a lot
