简体   繁体   中英

What is the python-jenkins wrapper commands for cancelling queued build and rebuild a previous build?

I am using python-jenkins wrapper to operate on Jenkins jobs from my python project. Most of the operations like building a job, deleting the build and so on have a python command in the documentation, but there is no such command available for rebuilding an old build using python as backend , can someone pls suggest the piece of code for it that I can use?

Another issue is with the cancel_queue() api of python-jenkins package, it takes a job id as a parameter, where can I find that id?

    def cancel_queue(self, id):
        '''Cancel a queued build.

        :param id: Jenkins job id number for the build, ``int``
        '''
        # Jenkins seems to always return a 404 when using this REST endpoint
        # https://issues.jenkins-ci.org/browse/JENKINS-21311
        try:
            self.jenkins_open(
                requests.Request(
                    'POST', self._build_url(CANCEL_QUEUE, locals()),
                    headers={'Referer': self.server}))
        except NotFoundException:
            # Exception is expected; cancel_queue() is a best-effort
            # mechanism, so ignore it
            pass

this is the code for the cancel_queue api, which id is this? Is there any other way to cancel the builds which are present in the queue at a time?

Thanks

So I learnt this the hard-way, Jenkins has its own queue_id which we can read it using python-jenkins wrapper. For example:

server = jenkins.Jenkins(URL, username=USER, password=PASSWORD)
queue_id = server.get_build_info(job_name, build_no)['queueId']

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