Skip to content

[JENKINS-64356] legacyIds missing when creating jobs via REST API or CLI #11833

@jenkins-infra-bot

Description

@jenkins-infra-bot

When creating a new job from the REST API using an XML file:

curl -u : \
	 -H "Content-Type:application/xml" \
	 -X POST http://jenkins.example.com/createItem?name=TEST_JOB \
	 -d @​config.xml

The job is correctly created BUT the builds directory does not contains the legacyIds file. The same happens when using the create-job command with the Jenkins CLI, we see the same behavior.

When creating a job from the UI however, the legacyIds is correctly added.

Impact

The absence of the legacyIds file cause the RunIdMigrator to "migrate" that job on the next startup.

jenkins.model.RunIdMigrator#migrate: Migrating build records in /builds

If many jobs are created using the REST API, this can slow down the next startup considerably. Some users that are automating the creating of items could be impacted.

Workaround

Create the job first "from scratch" then update the XML file:

# create a pipeline job from scratch
curl -X POST \
	 -u : \
	 -H "Content-Type:application/x-www-form-urlencoded" \
	 "http://jenkins.example.com/createItem?name=TEST_JOB&mode=org.jenkinsci.plugins.workflow.job.WorkflowJob"

# update the job configuration by providing the XML
curl -X POST \
	 -u : \
	 -H "Content-Type:application/xml" \
	 -d @​config.xml \
	 "http://jenkins.example.com/job/TEST_JOB/config.xml"

Further Note

The "RunIdMigrator" is instantiated in Job and AbstractProject when the Item#onCreatedFromScratch is called. But this is not called when using the REST API to copy a job or to create an item from XML:


Originally reported by allan_burdajewicz, imported from: legacyIds missing when creating jobs via REST API or CLI
  • assignee: mawinter69
  • status: Closed
  • priority: Minor
  • component(s): core
  • label(s): hacktoberfest, help-wanted, newbie-friendly
  • resolution: Fixed
  • resolved: 2024-05-27T17:44:43+00:00
  • votes: 4
  • watchers: 7
  • imported: 2025-11-24
Raw content of original issue

When creating a new job from the REST API using an XML file:

curl -u <user>:<pass> \
	 -H "Content-Type:application/xml" \
	 -X POST http://jenkins.example.com/createItem?name=TEST_JOB \
	 -d @config.xml

The job is correctly created BUT the builds directory does not contains the legacyIds file. The same happens when using the create-job command with the Jenkins CLI, we see the same behavior.

When creating a job from the UI however, the legacyIds is correctly added.

Impact

The absence of the legacyIds file cause the RunIdMigrator to "migrate" that job on the next startup.

jenkins.model.RunIdMigrator#migrate: Migrating build records in <pathToJobDirectory>/builds

If many jobs are created using the REST API, this can slow down the next startup considerably. Some users that are automating the creating of items could be impacted.

Workaround

Create the job first "from scratch" then update the XML file:

# create a pipeline job from scratch
curl -X POST \
	 -u <user>:<pass> \
	 -H "Content-Type:application/x-www-form-urlencoded" \
	 "http://jenkins.example.com/createItem?name=TEST_JOB&mode=org.jenkinsci.plugins.workflow.job.WorkflowJob"

# update the job configuration by providing the XML
curl -X POST \
	 -u <user>:<pass> \
	 -H "Content-Type:application/xml" \
	 -d @config.xml \
	 "http://jenkins.example.com/job/TEST_JOB/config.xml"

Further Note

The "RunIdMigrator" is instantiated in Job and AbstractProject when the Item#onCreatedFromScratch is called. But this is not called when using the REST API to copy a job or to create an item from XML:

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions