Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60835

Publish information about currently running builds via API

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • swarm-plugin
    • None
    • 3.21

      When using slave.jar, build nodes publish information about currently running builds via the Jenkins API. I'm not super well-versed in the API internals, but as far as I can tell, this involves publishing extra information for each executor. Otherwise, Jenkins replaces this with a PlaceholderTask, which doesn't contain any information about what is actually building, and the API consumer can only see if the executor is idle or not.

      Effectively, this means that API calls such as [{{get_running_builds}} in the python-jenkins API|]https://python-jenkins.readthedocs.io/en/latest/api.html#jenkins.Jenkins.get_running_builds return an empty list, which is not terribly useful.

          [JENKINS-60835] Publish information about currently running builds via API

          Basil Crow added a comment -

          Hey nre_ableton, as far as I can tell this should be working. Can you please provide a more detailed set of steps to reproduce the issue?

          Basil Crow added a comment - Hey nre_ableton , as far as I can tell this should be working. Can you please provide a more detailed set of steps to reproduce the issue?

          Basil Crow added a comment -

          Failed to reproduce the issue with 3.21. First I started a Swarm client with java -jar swarm-client-3.21.jar -master ${JENKINS_URL} -name swarm-test. Then I created a Pipeline job as follows:

          pipeline {
             agent {
                 label 'swarm-test'
             }
          
             stages {
                stage('Hello') {
                   steps {
                      sh 'sleep 99999'
                   }
                }
             }
          }
          

          I started the pipeline and verified the job was building and sleep(1) was running on the Swarm agent.

          Next I exercised the get_running_builds() API from python-jenkins as was reported to be problematic:

          import jenkins
          
          server = jenkins.Jenkins('http://localhost:8080', username='myuser', password='mypassword')
          user = server.get_whoami()
          version = server.get_version()
          print('Hello %s from Jenkins %s' % (user['fullName'], version))
          
          builds = server.get_running_builds()
          print(builds)
          

          According to the bug report, this would have returned an empty list. But it instead returned the running build, which is the correct behavior:

          Hello myuser from Jenkins 2.222.4
          [{'name': 'test', 'number': 2, 'url': '${JENKINS_URL}/job/test/1/', 'node': 'swarm-test', 'executor': 6}]
          

          Basil Crow added a comment - Failed to reproduce the issue with 3.21. First I started a Swarm client with java -jar swarm-client-3.21.jar -master ${JENKINS_URL} -name swarm-test . Then I created a Pipeline job as follows: pipeline { agent { label 'swarm-test' } stages { stage('Hello') { steps { sh 'sleep 99999' } } } } I started the pipeline and verified the job was building and sleep(1) was running on the Swarm agent. Next I exercised the get_running_builds() API from python-jenkins as was reported to be problematic: import jenkins server = jenkins.Jenkins('http://localhost:8080', username='myuser', password='mypassword') user = server.get_whoami() version = server.get_version() print('Hello %s from Jenkins %s' % (user['fullName'], version)) builds = server.get_running_builds() print(builds) According to the bug report, this would have returned an empty list. But it instead returned the running build, which is the correct behavior: Hello myuser from Jenkins 2.222.4 [{'name': 'test', 'number': 2, 'url': '${JENKINS_URL}/job/test/1/', 'node': 'swarm-test', 'executor': 6}]

          Nik Reiman added a comment -

          Hi – I'll try to reproduce this, but currently I can't update to Swarm Client 3.21 because of https://issues.jenkins-ci.org/browse/INFRA-2637. As soon as that is fixed, I'll grab a JAR file and try with this release.

          Nik Reiman added a comment - Hi – I'll try to reproduce this, but currently I can't update to Swarm Client 3.21 because of https://issues.jenkins-ci.org/browse/INFRA-2637 . As soon as that is fixed, I'll grab a JAR file and try with this release.

          Nik Reiman added a comment -

          This does indeed seem to be working as of version 3.21!

          Nik Reiman added a comment - This does indeed seem to be working as of version 3.21!

          Basil Crow added a comment -

          Working as of 3.21 (and possibly earlier).

          Basil Crow added a comment - Working as of 3.21 (and possibly earlier).

            Unassigned Unassigned
            nre_ableton Nik Reiman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: