> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Job Fetch Ingress URL amp Integration testing

> This guide extends a GitLab CI pipeline by adding an integration testing job to verify service endpoints after deploying to Kubernetes.

In this guide, we’ll extend our GitLab CI pipeline by adding an integration testing job. After deploying to Kubernetes, we’ll extract the Ingress host URL, save it as a dotenv report, and consume it in downstream tests to verify our service endpoints.

***

## 1. Define the Integration Testing Job

Begin by declaring a `k8s_dev_integration_testing` job in the `dev-deploy` stage. This job installs `curl` and `jq`, then probes the `/live` and `/ready` endpoints to confirm service health:

```yaml theme={null}
k8s_dev_integration_testing:
  stage: dev-deploy
  image: alpine:3.7
  before_script:
    - apk --no-cache add curl jq
  script:
    - curl -s -k https://$INGRESS_URL/live  | jq -r .status | grep -i live
    - curl -s -k https://$INGRESS_URL/ready | jq -r .status | grep -i ready
```

***

## 2. Capture the Ingress Host URL in CI

After your application manifests are applied, list the Ingress resource to confirm its host:

```bash theme={null}
kubectl -n development get ing
```

```plain theme={null}
NAME           CLASS    HOSTS                                          ADDRESS         PORTS   AGE
solar-system   <none>   solar-system-development.139.84.208.48.nip.io 139.84.208.48   80,443  39m
```

Extract the hostname via JSONPath:

```bash theme={null}
kubectl -n development get ing -o jsonpath="{.items[0].spec.tls[0].hosts[0]}"
```

Automate this in your deploy job and append the result to a dotenv file:

```yaml theme={null}
k8s_dev_deploy:
  stage: dev-deploy
  image: alpine:3.7
  script:
    - export KUBECONFIG=$DEV_KUBE_CONFIG
    - kubectl version -o yaml
    - kubectl config get-contexts
    - kubectl get nodes
    - export INGRESS_IP=$(kubectl -n ingress-nginx get svc ingress-nginx-controller \
        -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
    - echo "🔍 Ingress IP: $INGRESS_IP"
    - kubectl -n $NAMESPACE create secret generic mongo-db-creds \
        --from-literal=MONGO_URI=$MONGO_URI \
        --from-literal=MONGO_USERNAME=$MONGO_USERNAME \
        --from-literal=MONGO_PASSWORD=$MONGO_PASSWORD \
        --save-config --dry-run=client -o yaml | kubectl apply -f -
    - for manifest in kubernetes/manifest/*.yaml; do
        envsubst < "$manifest" | kubectl apply -f -
      done
    - echo "INGRESS_URL=$(kubectl -n $NAMESPACE get ing \
        -o jsonpath='{.items[0].spec.tls[0].hosts[0]}')" >> app_ingress_url.env
  artifacts:
    reports:
      dotenv: app_ingress_url.env
```

<Callout icon="lightbulb" color="#1CB2FE">
  By registering `app_ingress_url.env` as a dotenv report, GitLab exposes `INGRESS_URL` as a CI variable for subsequent jobs.
</Callout>

<Frame>
  ![The image shows a GitLab documentation page about artifacts:reports:dotenv, detailing how environment variables are collected and used in CI/CD pipelines. The page includes rules and exceptions for handling .env files.](https://kodekloud.com/kk-media/image/upload/v1752877206/notes-assets/images/GitLab-CICD-Architecting-Deploying-and-Optimizing-Pipelines-Job-Fetch-Ingress-URL-amp-Integration-testing/gitlab-artifacts-reports-dotenv.jpg)
</Frame>

***

## 3. Consume the Ingress URL in Integration Tests

Now update the integration testing job to depend on the deploy job. This ensures that `INGRESS_URL` is available:

```yaml theme={null}
k8s_dev_integration_testing:
  stage: dev-deploy
  needs:
    - k8s_dev_deploy
  image: alpine:3.7
  before_script:
    - apk --no-cache add curl jq
  script:
    - echo "Using Ingress URL: $INGRESS_URL"
    - curl -s -k https://$INGRESS_URL/live  | jq -r .status | grep -i live
    - curl -s -k https://$INGRESS_URL/ready | jq -r .status | grep -i ready
```

***

## 4. Visualize the Pipeline

After committing your `.gitlab-ci.yml`, your pipeline in the **dev-deploy** stage will include two sequential jobs:

<Frame>
  ![The image shows a GitLab Pipeline Editor interface with a successful pipeline visualization, including stages for containerization and deployment.](https://kodekloud.com/kk-media/image/upload/v1752877207/notes-assets/images/GitLab-CICD-Architecting-Deploying-and-Optimizing-Pipelines-Job-Fetch-Ingress-URL-amp-Integration-testing/gitlab-pipeline-editor-successful-visualization.jpg)
</Frame>

Upon completion, both jobs report success:

<Frame>
  ![The image shows a GitLab CI/CD pipeline interface for a NodeJS project called "Solar System," displaying successful stages for containerization and deployment.](https://kodekloud.com/kk-media/image/upload/v1752877208/notes-assets/images/GitLab-CICD-Architecting-Deploying-and-Optimizing-Pipelines-Job-Fetch-Ingress-URL-amp-Integration-testing/gitlab-cicd-nodejs-solar-system.jpg)
</Frame>

***

## References

* [GitLab CI/CD Pipelines](https://docs.gitlab.com/ee/ci/pipelines/)
* [GitLab artifacts:reports:dotenv](https://docs.gitlab.com/ee/ci/yaml/#artifactsreportsdotenv)
* [kubectl Overview](https://kubernetes.io/docs/reference/kubectl/overview/)
* [JSONPath in kubectl](https://kubernetes.io/docs/reference/kubectl/jsonpath/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/gitlab-ci-cd-architecting-deploying-and-optimizing-pipelines/module/df17ec22-8cda-4af7-af44-10f9f061d4a8/lesson/481b65e9-0fe9-4981-9229-b304b205fc61" />
</CardGroup>
