0

1) I am using Jenkins API to trigger a job, so when my monitoring tool sensu sends request Jenkins API to trigger jenkins JOb the build starts. 2) I have tried even manually by hitting buildnow instead of using API calls to make sure that it is not API call problem.

What does my build contain? It runs on Master and runs a ansible play-book with help of ansible plugin

Problem: Once the build is complete it is successful it automatically triggers another build with no reason again and runs the build again. And it is a simple job configuration which runs on master and runs ansible-playbook with help of Jenkins provided plugin

Any one could help me in what might be the issue? Jenkins Version: 2.89.3 Ansible plugin: 0.8

Also i could see for a jenkins job Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz for a single build

Cena
  • 55
  • 3
  • 8
  • Hi! I was checking the Ansible Plugin 0.8 and I found it "incomplete". Are you opened to other options within Jenkins? – imjoseangel May 17 '18 at 18:19
  • Sorry I dint get you Ansible plugin 0.8 incomplete in the sense? I need to run the play book from jenkins that is the only way i could think off – Cena May 17 '18 at 23:10
  • I didn’t want to say that is not working properly. i can give you a solution without the plugin but I want to be sure that is an option. – imjoseangel May 18 '18 at 06:14
  • I can suggest them the other solution, so can you please tell me that – Cena May 18 '18 at 16:13
  • Also i could see for a jenkins job Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz for a single build – Cena May 18 '18 at 16:13

3 Answers3

0

Does this issue happen when you build it manually also ?? if that's the case, then I would just looking into the configuration of Jenkins build and ensure that you haven't selected the option Build other project's in the Post Build section and mentioned the same project :P

EDITED

jenkins job Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz for a single build

enter image description here

If you are facing the above issue then it happens because the project is been triggered more than once in my case, I have clicked on the job twice hence you see that started by admin twice because you would have checked the option
Do not allow concurrent builds

Jenkins has that issue where there is a slight delay to see the build happening when you click on a build project, hence making you click on it again.

rohit thomas
  • 2,302
  • 11
  • 23
  • Yes It happens when i build manually but not every time. The post build section is not configured so that should not be the issue – Cena May 18 '18 at 16:12
  • 1
    Also i could see for a jenkins job Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz Started by user xyz for a single build – Cena May 18 '18 at 16:16
  • Can you please add the ansible script so that I can give you a reason what might be causing the issue...also confirm that your project is not called/trying to be called parallel and is it a multiJob by chance ?? – rohit thomas May 19 '18 at 01:20
0

Instead of using the Ansible plugin, I recommend doing the Jenkins way:

Create a pipeline from a Jenkinsfile with something like:

pipeline {
    parameters {
        string(name: 'Parameter1', defaultValue: 'value1', description: 'Parameter1?')
        string(name: 'Parameter2', defaultValue: 'value2', description: 'Parameter2?')
        string(name: 'Parameter3', defaultValue: 'value3', description: 'Parameter3?')

    }

    agent any

    options {
        ansiColor('xterm')
        timestamps()
    }

    stages {
        stage('Run Ansible Playbook') {
            steps {
                script {
                    retry (1) {
                        try {

                            echo "Build ${params.Parameter1} on ${params.Parameter2}"

                            sh "export ANSIBLE_FORCE_COLOR=true && \
                                ansible-playbook -vv \
                                                -i inventories/hosts \
                                                -e \"var1=${Parameter1}\" \
                                                -e \"var2=${Parameter2}\" \
                                                -e \"var3=${Parameter3}\" \
                                                --vault-password-file ~/.ansible/vaultpass.txt \
                                                playbooks/main.yml"
                        }
                        catch (exception) {
                            throw exception
                        }

                        finally {
                            sh "export ANSIBLE_FORCE_COLOR=true && \
                                ansible-playbook -vv \
                                                -i inventories/hosts \
                                                -e \"var1=${Parameter1}\" \
                                                -e \"var2=${Parameter2}\" \
                                                -e \"var3=${Parameter3}\" \
                                                --vault-password-file ~/.ansible/vaultpass.txt \
                                                playbooks/clean.yml"
                        }
                    }
                }
            }
        }
    }
}

You can control your pipeline in a more clean an easy way than with the Ansible Plugin.

imjoseangel
  • 3,543
  • 3
  • 22
  • 30
-1

If you see a job getting triggered twice even when you manually trigger, it might be in the way the Jenkins job is configured. Make sure you have concurrent build disabled.

  • Open your Jenkins Job
  • Click Configure
  • Uncheck Execute concurrent builds if necessary
  • Click Save

enter image description here

ibaralf
  • 12,218
  • 5
  • 47
  • 69