apache / incubator-devlake

Apache DevLake is an open-source dev data platform to ingest, analyze, and visualize the fragmented data from DevOps tools, extracting insights for engineering excellence, developer experience, and community growth.
https://devlake.apache.org/
Apache License 2.0
2.57k stars 514 forks source link

[Bug][Jenkins] ValidateTaskOptions not working as expected #7600

Closed sstojak1 closed 3 months ago

sstojak1 commented 3 months ago

Search before asking

What happened

If jenkins job is not part of a folder import for that job will fail.

What do you expect to happen

Job import to pass.

How to reproduce

Create a job that is not part of a folder and run the import. It should fail with an error like this: error preparing task data for jenkins (404) Wraps: (2) error decoding response from https://{jenkins_host}/view/all/api/json?tree=jobs%5BfullName%2Cname%2Cclass%2Curl%2Ccolor%2Cbase%2Cjobs%2CupstreamProjects%5Bname%5D%5D%7B0%2C100%7D: raw response: <html> | <head> | <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/> | <title>Error 404 Not Found</title> | </head> | <body><h2>HTTP ERROR 404 Not Found</h2> | <table> | <tr><th>URI:</th><td>/view/all/api/json</td></tr> | <tr><th>STATUS:</th><td>404</td></tr> | <tr><th>MESSAGE:</th><td>Not Found</td></tr> | <tr><th>SERVLET:</th><td>Stapler</td></tr> | </table> | <hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 10.0.13</a><hr/> | | </body> | </html> | (404) Wraps: (3) invalid character '<' looking for beginning of value Wraps: (4) invalid character '<' looking for beginning of value Error types: (1) *hintdetail.withDetail (2) *hintdetail.withDetail (3) *hintdetail.withDetail (4) *json.SyntaxError

Why is it failing like this? Because Devlake's ValidateTaskOptions didn't find a "/" in the job's fullName attribute, it sets the JobPath to "view/all/". This causes the import to fail with the stated error because that path cannot be found

Why is the logic set up like that - set to view/all/? I didn't find docs for that path. I'm only aware of api/ path that will list all jobs If job is set like this in case a job is part of a folder import will pass. Why not do the same for folderless jobs?

Anything else

No response

Version

v1.0.0-beta11

Are you willing to submit PR?

Code of Conduct

dosubot[bot] commented 3 months ago

The issue you're encountering with Jenkins job imports failing for jobs not part of a folder is due to the logic in DevLake's ValidateTaskOptions function. Specifically, when a job's fullName attribute does not contain a /, the function sets the JobPath to view/all/, which is not a valid path for folderless jobs, leading to a 404 error.

Here's the relevant code snippet from ValidateTaskOptions:

if i := strings.LastIndex(op.JobFullName, `/`); i >= 0 {
    op.JobName = op.JobFullName[i+1:]
    op.JobPath = `job/` + strings.Join(strings.Split(op.JobFullName[:i], `/`), `/job/`)

    if op.Class == WORKFLOW_MULTI_BRANCH_PROJECT {
        op.JobPath = `view/all/` + op.JobPath
    }

} else {
    op.JobName = op.JobFullName
    op.JobPath = `view/all`
}

For jobs not part of a folder, the else block sets op.JobPath to view/all, which is likely causing the import to fail because the path view/all might not be valid for folderless jobs [1].

The historical context for setting the default JobPath to view/all/ is to provide a default view path for Jenkins jobs that are not nested within any folders. This ensures that even if a job is not part of a folder structure, it can still be accessed and managed under the view/all path, which is a common default view in Jenkins for listing all jobs [1].

To address this issue, you might consider modifying the else block to construct a valid JobPath similar to how it is done for jobs within folders. This would involve ensuring that the path is correctly set for folderless jobs to avoid the 404 error.

To continue talking to Dosu, mention @dosu.

sstojak1 commented 3 months ago

There was an issue on our side since the view/all path was removed. After recreating it, the import finished successfully