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

Job created via REST API attaches to default view (regression in 2.475)

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • Jenkins=2.479.1
      Drop Down ViewsTabBar plugin=1.7
    • 2.485, 2.479.2

      Programmatically created jobs (via posting XML to url /createItem/api/json?name=my_job_name) now attached to default view in Jenkins (i can see them in /var/lib/jenkins/config.xml eather, section <views><listView><jobNames>).

      This behavior started since we've updated Jenkins from previous LTS (2.462.3) to current LTS (2.479.1)

      Steps to reproduce:

      1. upgrade to Jenkins 2.479.1
      2. prepare any valid job XML config (see below)
      3. curl -X POST -u "username:api-token" \
             -H "Content-Type: application/xml" \
             --data-binary @job.xml \
             "https://<jenkins_host>/createItem/api/json?name=my_job_name"
        

      Expected:
      Job doesn't attached to any view

      Actual:
      Job attached to default view

      job.xml example:

      <?xml version='1.1' encoding='UTF-8'?>
      <project>
        <description>tst job from API</description>
        <keepDependencies>false</keepDependencies>
        <properties/>
        <canRoam>true</canRoam>
        <disabled>false</disabled>
        <triggers/>
        <builders/>
        <publishers/>
        <buildWrappers/>
      </project>
      

      Jenkins settings:

      Job attached to default view:

          [JENKINS-74795] Job created via REST API attaches to default view (regression in 2.475)

          Mark Waite added a comment -

          Please provide more details so that others can duplicate the issue. "How to report an issue" describes the type of information to be included.

          Mark Waite added a comment - Please provide more details so that others can duplicate the issue. "How to report an issue" describes the type of information to be included.

          Mark Waite added a comment - - edited

          The description you've provided is not detailed enough for me to duplicate the problem. Please provide enough details so that the problem can be seen from a fresh Jenkins installation. The steps that I took while trying to duplicate the problem were:

          1. Create a plugins.txt file that lists the exact plugins and their versions (as generated by the script in "How to report an issue")
          2. Create a run-jenkins.sh shell script that downloads Jenkins 2.479.1 and the plugin versions in plugins.txt and runs Jenkins
          3. Run the run-jenkins.sh shell script and complete the setup wizard by installing no additional plugins and creating a user "mwaite" with password "mwaite"
          4. Define a view "a-list-view" that displays jobs that start with "a"
          5. Define a view "b-list-view" that displays jobs that start with "b"
          6. Configure "b-list-view" as the default view from "Manage Jenkins" -> "System"
          7. Create a local file with the Pipeline job configuration from pipeline-config.xml
          8. Download the Jenkins CLI from the /cli/ URL
          9. Create a new job with the Jenkins CLI using the command
            java -jar jenkins-cli.jar -s http://testing-b.markwaite.net:8080/ -auth mwaite:mwaite  create-job my-pipeline-$RANDOM < pipeline-config.xml
            
          10. Confirm that the newly created job does not appear in the default view. That is expected, since my default view is defined to only show jobs that start with the letter "b"

          Mark Waite added a comment - - edited The description you've provided is not detailed enough for me to duplicate the problem. Please provide enough details so that the problem can be seen from a fresh Jenkins installation. The steps that I took while trying to duplicate the problem were: Create a plugins.txt file that lists the exact plugins and their versions (as generated by the script in "How to report an issue") Create a run-jenkins.sh shell script that downloads Jenkins 2.479.1 and the plugin versions in plugins.txt and runs Jenkins Run the run-jenkins.sh shell script and complete the setup wizard by installing no additional plugins and creating a user "mwaite" with password "mwaite" Define a view "a-list-view" that displays jobs that start with "a" Define a view "b-list-view" that displays jobs that start with "b" Configure "b-list-view" as the default view from "Manage Jenkins" -> "System" Create a local file with the Pipeline job configuration from pipeline-config.xml Download the Jenkins CLI from the /cli/ URL Create a new job with the Jenkins CLI using the command java -jar jenkins-cli.jar -s http: //testing-b.markwaite.net:8080/ -auth mwaite:mwaite create-job my-pipeline-$RANDOM < pipeline-config.xml Confirm that the newly created job does not appear in the default view. That is expected, since my default view is defined to only show jobs that start with the letter "b"

          Andrey added a comment -

          I think it's about step 9:
          I 've created job using CLI and it's also OK.

          I suppose, to reproduce it should be done via Jenkins REST API using curl (or other http clients) like in my step [to reproduce] 3:

          curl -X POST -u "username:api-token" \
               -H "Content-Type: application/xml" \
               --data-binary @job.xml \
               "https://<jenkins_host>/createItem/api/json?name=my_job_name"

          Andrey added a comment - I think it's about step 9: I 've created job using CLI and it's also OK. I suppose, to reproduce it should be done via Jenkins REST API using curl (or other http clients) like in my step [to reproduce] 3: curl -X POST -u "username:api-token" \ -H "Content-Type: application/xml" \ --data-binary @job.xml \ "https://<jenkins_host>/createItem/api/json?name=my_job_name"

          Mark Waite added a comment -

          Thanks for the clarification. I can see the same problem when I use the REST API. I was not expecting any difference between the REST API and the command line interface.

          I extended my run-jenkins.sh script with the following shell function:

          JENKINS_URL=http://$(hostname):8080/
          
          function create_job_curl() {
            cookie_file=$(mktemp /tmp/JENKINS-74795.XXXXXX)
            crumb=$(curl --cookie-jar $cookie_file -u mwaite:mwaite -s ${JENKINS_URL}/crumbIssuer/api/xml?xpath=concat\(//crumbRequestField,%22:%22,//crumb\))
            echo Crumb is $crumb
            curl -s -H "$crumb" --cookie $cookie_file -u mwaite:mwaite -X POST -H "Content-Type: application/xml" --data-binary @pipeline-config.xml ${JENKINS_URL}/createItem/api/json?name=my-pipeline-curl-$RANDOM
          }
          

          Once Jenkins was started, I called that shell function with:

          # Queue a curl command to create a new job
          (sleep 43; create_job_curl) &
          

          The new job appears in the default view, even though the default view is defined initially to only display jobs that start with the letter 'b'.

          Mark Waite added a comment - Thanks for the clarification. I can see the same problem when I use the REST API. I was not expecting any difference between the REST API and the command line interface. I extended my run-jenkins.sh script with the following shell function: JENKINS_URL=http: //$(hostname):8080/ function create_job_curl() { cookie_file=$(mktemp /tmp/JENKINS-74795.XXXXXX) crumb=$(curl --cookie-jar $cookie_file -u mwaite:mwaite -s ${JENKINS_URL}/crumbIssuer/api/xml?xpath=concat\( //crumbRequestField,%22:%22,//crumb\)) echo Crumb is $crumb curl -s -H "$crumb" --cookie $cookie_file -u mwaite:mwaite -X POST -H "Content-Type: application/xml" --data-binary @pipeline-config.xml ${JENKINS_URL}/createItem/api/json?name=my-pipeline-curl-$RANDOM } Once Jenkins was started, I called that shell function with: # Queue a curl command to create a new job (sleep 43; create_job_curl) & The new job appears in the default view, even though the default view is defined initially to only display jobs that start with the letter 'b'.

          Mark Waite added a comment - - edited

          The first Jenkins weekly version with the new behavior is 2.475. Further bisecting will be needed to identify the commit in that release.

          Mark Waite added a comment - - edited The first Jenkins weekly version with the new behavior is 2.475. Further bisecting will be needed to identify the commit in that release.

          Mark Waite added a comment - - edited

          The first commit with the change is 7006cded. That is the commit that migrates from Jakarta EE 8 to Jakarta EE 9.

          Mark Waite added a comment - - edited The first commit with the change is 7006cded . That is the commit that migrates from Jakarta EE 8 to Jakarta EE 9.

          Mark Waite added a comment -

          I've written an automated test that shows the issue as part of https://github.com/jenkinsci/jenkins/pull/9933 . That test can be used to confirm the fix when it is ready.

          Mark Waite added a comment - I've written an automated test that shows the issue as part of https://github.com/jenkinsci/jenkins/pull/9933 . That test can be used to confirm the fix when it is ready.

            basil Basil Crow
            an_nikolaev Andrey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: