Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continuous integration switch for molecule role init #962

Closed
rgarrigue opened this issue Sep 20, 2017 · 7 comments
Closed

continuous integration switch for molecule role init #962

rgarrigue opened this issue Sep 20, 2017 · 7 comments

Comments

@rgarrigue
Copy link
Contributor

Issue Type

  • Feature request

Molecule and Ansible details

molecule 2.0.1
  • Molecule installation method: pip
  • Ansible installation method: pip

Desired Behaviour

molecule init role -r myrole --ci travis generating a .travis.yml, molecule init role -r myrole --ci circle generating the .circleci/ folder, etc.

Creating a new ansible role to be tested with molecule + travis, I though that I always end up c/c the same .travis.yml from my other roles, here is an example. I also imagin people using CircleCI or other continuous integration. Maybe that'ld be a nice thing for molecule to optionaly generate a working config for CI via that switch.

@retr0h
Copy link
Contributor

retr0h commented Sep 20, 2017

I don't use circle CI so don't really have much of a reason to implement this. If there is someone in the community that uses circle CI and can provide a generic file as a template, they are free to provide a PR to do so. However, not something I have the bandwidth to take on.

@r0ckyte
Copy link

r0ckyte commented Sep 22, 2017

am curious to know if molecule directly support jenkins ? or do need write custom wrapper script ?

@dj-wasabi
Copy link
Contributor

@r0ckyte

What do you mean with support Jenkins? You can run molecule with a Jenkins Job.

@r0ckyte
Copy link

r0ckyte commented Sep 24, 2017

@dj-wasabi - thanks , i didnt know that its able to run from jenkins. is it like running molecule as script or command in jenkins build stage ?

@dj-wasabi
Copy link
Contributor

I use jenkins-pipelines, so I can only show you my Jenkinsfile:

node() {
    try {
        stage ("Get Latest Code") {
            checkout scm
            sh 'git rev-parse HEAD > .git/commit-id'
        }
        stage ("Install Application Dependencies") {
            sh 'sudo pip install --upgrade ansible==${ANSIBLE_VERSION} molecule==${MOLECULE_VERSION} docker'
        }
        stage ("Executing Molecule lint") {
            sh 'molecule lint'
        }
        stage ("Executing Molecule create") {
            sh 'molecule create'
        }
        stage ("Executing Molecule converge") {
            sh 'molecule converge'
        }
        stage ("Executing Molecule idemotence") {
            sh 'molecule idempotence'
        }
        stage ("Executing Molecule verify") {
            sh 'molecule verify'
        }
        stage('Tag git'){
            def commit_id = readFile('.git/commit-id').trim()
            withEnv(["COMMIT_ID=${commit_id}"]){
                sh '''#!/bin/bash
                if [[ $(git tag | grep "^${$COMMIT_ID}$" | wc -l) -eq 1 ]]
                    then    echo "Tag already exists"
                    else    echo "Tag will be created"
                            git config user.name "jenkins"
                            git config user.email "jenkins@localhost"
                            git tag -a $COMMIT_ID -m "Added tagging"
                            git push --tags
                fi
                '''
            }
        }
        stage('Start Staging Job') {
            def commit_id = readFile('.git/commit-id').trim()
            withEnv(["COMMIT_ID=${commit_id}"]){
                build job: 'ansible-access-2-staging', wait: false, parameters: [string(name: 'COMMIT_ID', value: "${COMMIT_ID}") ]
            }
        }
    } catch(all) {
        currentBuild.result = "FAILURE"
        throw err
    }
}

I seperate the actions into their own stages, so I can easily see when a stage goes into error and if a stage is running slower/faster.

@r0ckyte
Copy link

r0ckyte commented Sep 24, 2017

Thanks alot @dj-wasabi

@retr0h
Copy link
Contributor

retr0h commented Sep 25, 2017

Feel free to open a PR to add documentation around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants