As developers, we can all relate to the experience of getting up to speed on a new tool or framework, and the frustrations (and joys!) that come with it. Speaking personally, I can easily recall my first experiences building CircleCI config.yml files, both 1.0 and 2.0, and the many iterations I went through while having the CircleCI configuration reference open on a separate screen. There was more trial-and-error involved than I’d like to admit.

Since the announcement of CircleCI 2.0, our team has continued to ship improvements to the onboarding experience to make it easier to get started, including functionality within the CircleCI CLI to validate a config.yml file locally. Our latest release to make this experience better is the Jenkinsfile converter.

What is the Jenkinsfile converter?

The Jenkinsfile converter is a tool to convert your Jenkinsfile into a CircleCI config.yml file. By loading your Jenkinsfile into the converter, you’ll immediately receive a formatted config.yml file that will take you most of the way to an optimal configuration with CircleCI.

It’s important to note that while the tool does its best to convert as much of a Jenkinsfile as it can, there are key differences that are not feasible to address through this tool. For instance, CircleCI doesn’t have a concept for plug-ins, and we’re unable to support the over 1,400 constantly evolving plug-ins in the Jenkins universe. While there will be a little bit of additional work to perform in order to get your build into optimal shape, the Jenkinsfile converter will have you well on your way. Let’s look at an example.

Here we have a simple Python project’s Jenkinsfile:

pipeline {
    agent none
    options {
        skipStagesAfterUnstable()
    }
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'python:2-alpine'
                }
            }
            steps {
                sh 'python -m py_compile sources/add2vals.py sources/calc.py'
            }
        }
        stage('Test') {
            agent {
                docker {
                    image 'qnib/pytest'
                }
            }
            steps {
                sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py'
            }
            post {
                always {
                    junit 'test-reports/results.xml'
                }
            }
        }
    }
}

After loading this Jenkinsfile into the converter, we’re presented with the following config.yml file:

version: 2.1
jobs:
  build:
    docker:
      - image: cimg/base:2020.08
    steps:
      - run:
          command: python -m py_compile sources/add2vals.py sources/calc.py
  test:
    docker:
      - image: cimg/base:2020.08
    steps:
      - run:
          command: py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py

workflows:
  version: 2
  build-and-test:
    jobs:
      - build
      - test:
          requires:
            - build

Here, the post command that would post the test results is not transferred to the CircleCI config.yml file. We’d need to add the store_test_results key to our config.yml file in order to bring this functionality into CircleCI.

  test:
    docker:
      - image: qnib/pytest
    steps:
      - run:
          command: py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py
	- store_test_results:
	    path: test-reports

The Jenkinsfile converter is located within the CircleCI developer hub, and is now available to all. This tool will help save you crucial time in getting started with CircleCI, whether you’re just trying it out, or transferring a project with a 2,000-line Jenkinsfile, and save you from the temptation of using trial-and-error to resolve configuration issues between the two services.

Note: Only declarative-style Jenkinsfiles are supported today, with no current plans to support scripted Jenkinsfiles. This is our first release, and we’d love to hear your feedback about what is and isn’t working well as we continue iterating on the functionality for this tool.

To learn more about this feature, see the links below: