dave-hagedorn / jenkins-runner

VS Code plugin to develop and run Jenkins Pipeline scripts
MIT License
30 stars 8 forks source link

TypeError: Cannot read property 'definition' of undefined #9

Open dave-hagedorn opened 5 years ago

dave-hagedorn commented 5 years ago

I have the same issue with the user included.

TypeError: Cannot read property 'definition' of undefined

When I try with the URL having a "/" at the end is trying to connect and then not do anything. But when I remove the "/" at the end of the URL I get the Type Error. I tried removing the parameters of the settings but still, it tries to pass #undefined as a parameter for the job.

Originally posted by @hari2m in https://github.com/dave-hagedorn/jenkins-runner/issues/1#issuecomment-496629369

dave-hagedorn commented 5 years ago

Hi there,

I'll need some more information to investigate - could you provide:

Thanks,

Dave

hari2m commented 5 years ago

This is what it says in the log.

[2019-06-16 09:33:58.465] [Jenkins] [info] Creating Jenkins instance @url=https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI, with user=*******, password=****
[2019-06-16 09:33:58.474] [Jenkins] [info] Creating pipeline build using job jenkinsRunner @https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI, with params undefined
[2019-06-16 09:33:58.475] [Jenkins] [info] Fetching remote XML config for job jenkinsRunner @https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI
[2019-06-16 09:34:10.546] [Jenkins] [error] Error starting job jenkinsRunner #undefined @https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI}: Error: jenkins: job.config: getaddrinfo ENOTFOUND jenkins.domain.com jenkins.domain.com:443
[2019-06-16 09:34:12.860] [Jenkins] [info] Stopping job jenkinsRunner #undefined @https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI
[2019-06-16 09:34:12.861] [Jenkins] [info] Stopping job jenkinsRunner #undefined @https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI

The job that I am trying to build is a multi-branch pipeline. and my configuration looks like below.

 "jenkins-runner.hostConfigs": {
        "master": {
            "url": "https://jenkins.domain.com/jenkins/job/Dev/job/Columbus/job/ColumbusAPI",
            "user": "***",
            "password": "***"
        }
    },
    "jenkins-runner.jobs": {
        "Tester": {
            "isDefault": true,
            "runWith": ["master"],
            "name": "jenkinsRunner"
        }
    },
    "jenkins.pipeline.linter.connector.strictssl": false,
    "terminal.integrated.rendererType": "dom"
dave-hagedorn commented 5 years ago

Hi there,

Thanks for the info. multi-branch pipelines are not currently supported - more info here. I'm actually not sure if this is possible since Jenkins sources the Jenkinsfile itself from SCM, not the jobs' config. This plugin works by modifying the pipeline script defined in the job's config in Jenkins.

This is similar to #11. I'll leave this open to see if there's any way I can fix this - or at least show a better error to the user.

Thanks!

dave-hagedorn commented 5 years ago

Also - I noticed your host url seems to be incorrect - you want the root URL of your jenkins instance - ex "url": "https://jenkins.domain.com/

hari2m commented 5 years ago

I have tried using the base url. But it gave me error saying unable to find the job, then I tried giving the location of the job and it worked and so I am using that url. Will give a try to see if it can find that without.

dave-hagedorn commented 5 years ago

Is your job located in a folder?

Does it work if you use the Jenkins URL, but specify the path to the job as the job's name - as documented here?

hari2m commented 5 years ago

Yes, It's inside a folder. I do not know about the folder path in the name thing. I will start using that.

dave-hagedorn commented 5 years ago

I've updated the docs for the next 1.3.0 release. Are there any other problems you're seeing?

hari2m commented 5 years ago

Thanks. No other issues observed.

davidmoshal commented 4 years ago

same error as the title in this issue. not sure what object is undefined. better debugging info would be appreciated.

tndhagedorn commented 4 years ago

Do any of the steps/comments in this issue resolve your issue?

aguckenber-chwy commented 1 year ago

I just got this issue. I am running Jenkins in docker locally so it is pretty easy to replicate.

"jenkins-runner.hostConfigs": {
    "local": {
        "url": "http://jenkins:8080",
        "user": "admin",
        "password": "admin"
    }
},
"jenkins-runner.jobs": {
    "test-job": {
        "isDefault": true,
        "runWith": "local",
        "name": "test-job"
    }
}
[2023-05-24 14:00:01.828] [Jenkins] [info] Creating Jenkins instance @url=http://jenkins:8080, with user=admin, password=****
[2023-05-24 14:00:01.830] [Jenkins] [info] Creating pipeline build using job test-job @http://jenkins:8080, with params undefined
[2023-05-24 14:00:01.830] [Jenkins] [info] Fetching remote XML config for job test-job @http://jenkins:8080
[2023-05-24 14:00:01.933] [Jenkins] [info] Parsing and updating XML with new pipeline script
[2023-05-24 14:00:01.935] [Jenkins] [error] Error starting job test-job #undefined @http://jenkins:8080}: TypeError: Cannot read properties of undefined (reading 'definition')
[2023-05-24 14:00:07.843] [Jenkins] [info] Stopping job test-job #undefined @http://jenkins:8080
[2023-05-24 14:00:07.845] [Jenkins] [info] Stopping job test-job #undefined @http://jenkins:8080

The xml for the job it is fetching:

<project>
    <description />
    <keepDependencies>false</keepDependencies>
    <properties />
    <scm class="hudson.scm.NullSCM" />
    <canRoam>true</canRoam>
    <disabled>false</disabled>
    <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
    <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
    <triggers />
    <concurrentBuild>false</concurrentBuild>
    <builders />
    <publishers />
    <buildWrappers />
</project>

We are using an older Jenkins 2.387.1-lts which may be why this wasn't east to reproduce.

aguckenber-chwy commented 1 year ago

Turns out I created Freestyle project which has the XML above. If I create a pipeline then the XML looks as the code expects and works.