How to run a CICD pipeline with Jenkinsfile,Ansible roles inside a POD Container

5/29/2020

I would like to create a CICD pipeline inside a POD container on a centralized Kubernetes cluster.

CICD code structure:-

- ansibleroles
    - Instance  creation role
    - Application deployment role
    .
    .
- Makefile
- Jenkinsfile
.
.

Jenkinsfile is referring to makefile and makefile to the specific ansible role folder as defined.

Please find the part of Jenkinsfile below:

podTemplate(label: label, containers: [
  containerTemplate(name: 'python', image: 'python:3.7', command: 'cat', ttyEnabled: true)
],
volumes: [
  hostPathVolume(mountPath: '/opt/tmp', hostPath: '/tmp/jenkins/.python')
]) {
  node(label) {
    checkout scm
     stage('Test') {
      try {
        container('python') {
          sh """
            python3 -m pip install ansible
            python3 -m pip install make
            python3 -m pip install awscli
            make instance-installation
            """
        }
      }
      catch (exc) {
        println "Failed to test - ${currentBuild.fullDisplayName}"
        throw(exc)
      }

Whatever I put inside container python would work, but how to do it for bigger code. I have 6-7 different ansible roles which i would like to make work inside a container, writing all together inside Jenkinsfile doesn't seems feasible option. Is there any way we can create whole cicd structure inside POD or globalized the container values outside container.

-- takshika jambhule
ansible
docker
jenkins-pipeline
kubernetes
pod

0 Answers