简体   繁体   中英

Jenkins pipeline - Trigger a new build for a given job

I have two Jenkins pipelines, named A and B . Both use the same docker container, named C1 . The job A looks like this:

pipeline {
    agent {
        node {
            label 'c1'
        }
    }
    stages {
        ...
    }
    post {
        always {
            script {
                echo "always"
            }
        }
        success {
            script {
                echo "success"
            }
        }
        failure {
            script {
                echo "failure"
            }
        }
        unstable { 
            script {
                echo "unstable"
            }
        }
    }
}

The only difference is in the job B . This, in the post action always calls the job A , like this:

build job: 'A/master', parameters: [ string(name: 'p1', value: params["p1"])  ]

The error occures by starting the job A , saying:

Error when executing success post condition:
hudson.AbortException: No item named A/master found

And also, by listing the parent folders, it is evident that there is no folder for job A .

How could I solve this problem?

KI

The solution for this problem is the folder name in which these jobs are located. So, the name of the job is test/A/master .

From your comments I've read you're using the Gitea plugin to receive the repositories from your Gitea instance. Gitea repositories are organized per user/organization like Github does.

Once you've added a Gitea project (user/organization) via the Jenkins plugin the full name of one of the jobs will be:

<user_or_orga>/<repository_name>/<branch>

For example for the user name "crash", where the repository "stackoverflow" belongs to, it would be (for the master branch):

crash/stackoverflow/master

To get a list of all items including all full job names you can run this in the script console (under Manage Jenkins):

Jenkins.instance.getAllItems(AbstractItem.class).each {      
    println(it.fullName)
};

PS for the Bitbucket plugin and others it's the same rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM