Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorials/jenkins/ansible-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In the _New credentials_ form:

## Configure the pipeline

First, create a new pipeline via [New Item](http://localhost:8080/view/all/newJob) button in the rigth side menu of the Jenkins dashboard. The name of the pipeline could be for example `Animals` and it should be an pipeline.
First, create a new pipeline via [New Item](http://localhost:8080/view/all/newJob) button in the right side menu of the Jenkins dashboard. The name of the pipeline could be for example `Animals` and it should be an pipeline.

In the configure pipeline view, scroll to the bottom and under Pipeline sub-header select `Pipeline script from SCM`. SCM type should be `Git` and Repository URL the url of this repository: `https://github.com/cicd-tutorials/cicd-tutorials.net.git`. Ensure that branch specifier includes `main` branch of the repository and modify the Script Path to be `docs/tutorials/jenkins/ansible-kubernetes/Jenkinsfile`.

Expand All @@ -47,6 +47,6 @@ After the Ansible playbook has been executed, the pipeline runs [wait-until-serv
---8<--- "docs/tutorials/jenkins/ansible-kubernetes/wait-until-service-up.sh"
```

You can find the URL of the created load-balancer from the console output of the build. Open the application with your browser or user curl to see the application response.
You can find the URL of the created load-balancer from the console output of the build. Open the application with your browser or use curl to see the application response.

In addition, after the first execution Jenkins should have updated the project configuration to contain parameters defined in the pipeline and we can configure the image tag in _Build with Parameters_ menu.
56 changes: 56 additions & 0 deletions docs/tutorials/jenkins/opentofu-kubernetes/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
String d = "docs/tutorials/jenkins/opentofu-kubernetes"
def status = 0

pipeline {
agent any
environment {
KUBE_CONFIG_PATH = credentials('kubeconfig')
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/cicd-tutorials/feedback.git'
}
}
stage('Plan') {
agent { docker {
image 'ghcr.io/opentofu/opentofu:latest'
args '--entrypoint=""'
reuseNode true
} }
steps {
dir("iac/tf") {
sh "tofu init -no-color"
script {
status = sh returnStatus: true, script: "tofu plan -no-color -detailed-exitcode -out ${env.BUILD_TAG}.plan"
}
stash includes: "${env.BUILD_TAG}.plan", name: 'plan'
}
}
}
stage('Apply') {
agent { docker {
image 'ghcr.io/opentofu/opentofu:latest'
args '--entrypoint=""'
reuseNode true
} }
when {
beforeInput true
equals expected: 2, actual: status
}
input {
message 'Apply the plan?'
ok 'Apply'
}
steps {
dir("iac/tf") {
unstash 'plan'
sh """
tofu init -no-color
tofu apply -no-color ${env.BUILD_TAG}.plan
"""
}
}
}
}
}
27 changes: 27 additions & 0 deletions docs/tutorials/jenkins/opentofu-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
description: Tutorial on how to configure a Jenkins pipeline that deploys an feedback application to a Kubernetes cluster.
---

# Deploy application to Kubernetes with OpenTofu

This tutorial contains a pipeline that deploys an feedback application to a Kubernetes cluster.

## Prerequisites and preparing the Jenkins instance

See [Deploy application to Kubernetes with Ansible](../ansible-kubernetes/) tutorial for prerequisites and instruction for configuring access from the Jenkins instance to the Kubernetes cluster.

## Configure the pipeline

First, create a new pipeline via [New Item](http://localhost:8080/view/all/newJob) button in the right side menu of the Jenkins dashboard. The name of the pipeline could be for example `Feedback-Deploy` and it should be an pipeline.

In the configure pipeline view, scroll to the bottom and under Pipeline sub-header select `Pipeline script`. Copy the script from below to the _Script_ textarea.

The pipeline deploys an example application to a Kubernetes cluster using OpenTofu configuration. The pipeline will first plan the deployment and then ask approval from an user before applying the plan to the target cluster.

```groovy title="Jenkinsfile"
---8<--- "docs/tutorials/jenkins/opentofu-kubernetes/Jenkinsfile"
```

After you have created the pipeline, try to execute it by clicking _Build Now_. The pipeline should have deployed the example application.

You can find the URL of the created application from the console output of the build. Open the application with your browser or use curl to see the application response.
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ nav:
- Jenkins:
- ./tutorials/jenkins/jenkins-host-docker/README.md
- ./tutorials/jenkins/ansible-kubernetes/README.md
- ./tutorials/jenkins/opentofu-kubernetes/README.md
- ./tutorials/jenkins/build-status-pipelines/README.md
- ./tutorials/jenkins/parallel-robot-pipeline/README.md
- ./tutorials/jenkins/sonarqube-jenkins/README.md
Expand Down