Jenkins job triggered twice

2019-08-16 07:56发布

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

3条回答
beautiful°
2楼-- · 2019-08-16 08:38

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.

查看更多
贪生不怕死
3楼-- · 2019-08-16 08:42

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.

查看更多
疯言疯语
4楼-- · 2019-08-16 08:50

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

查看更多
登录 后发表回答