tabeyti / jenkins-jack

Jack into your Jenkins to execute Pipeline scripts, provide Pipeline step autocompletions, pull Shared Library step documenation, run console groovy scripts across multiple nodes, and more! Honestly, not that much more.
Other
97 stars 32 forks source link

Extension issue #28

Closed VitekVlcek-Broadcom closed 3 years ago

VitekVlcek-Broadcom commented 4 years ago

I did same steps like in https://github.com/tabeyti/jenkins-jack/issues/23. I do have toke defined properly because I see nodes, and builds. But I don't have the privilege to create Jenkins jobs anywhere. I can create then only in certain Jenkins folder like https://jenkins/job/MyArea/

Error message:

{
    "messages": [],
    "activationTimes": {
        "codeLoadingTime": 597,
        "activateCallTime": 18,
        "activateResolvedTime": 33,
        "activationReason": {
            "startup": true,
            "extensionId": {
                "value": "tabeyti.jenkins-jack",
                "_lower": "tabeyti.jenkins-jack"
            },
            "activationEvent": "*"
        }
    },
    "runtimeErrors": [
        {
            "name": "Error",
            "message": "jenkins: job.create: forbidden"
        }
    ]
}

Unrelated Another problem is that I have to change type of Jenkinsfile from JenkinsFile to Groovy. Can you allow pipeline jack even for JenkinsFile image

tabeyti commented 3 years ago

Hey @VitekVlcek-Broadcom ,

Apologies for such a late reply.

I'm not sure if this is an extension issue or a permissions issue on the Jenkins host. Does your user have admin level permissions on the Jenkins host?

VitekVlcek-Broadcom commented 3 years ago

I don't have admin privileges to jenkins host. However, I can create new jobs within the specifics folder eg: https://jenkins/job/MyArea/ but no in https://jenkins/job/OtherArea/ V

tabeyti commented 3 years ago

Here's what I would do @VitekVlcek-Broadcom

  1. Make sure your extensions is updated to 1.1.0 which has folder support for Pipeline jobs.
  2. On your Jenkins host, create your job manually in your folder (e.g. https://jenkins/job/MyArea/myjob).
  3. In VSCode, open your script (e.g. myjob.groovy). In the same directory as your script, check if a Pipeline config file already exists for this script (e.g. .myjob.config.json). If not make one (same directory as the script) with the following info:
    {
    "name": "myjob",
    "params": null,
    "folder": "MyArea"
    }
  4. Run your script

Let me know if this works for you. Currently, the extension doesn't have the ability to specify a folder on job creation, but it can link to a job in a folder which already exists.

VitekVlcek-Broadcom commented 3 years ago

Hi I performed steps 1-3.

The password is correct because I can pipelines and jobs from Jenkins.

tabeyti commented 3 years ago

Hey @VitekVlcek-Broadcom ,

If this is the CSRF protection issue mentioned in other tickets, then this should be fixed in version 1.1.1. If you could update your extension and validate for me, I'd appreciate it.

VitekVlcek-Broadcom commented 3 years ago

this seems to be still broken.

StatusCodeError: 404 - "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 404 Not Found</title>\n</head>\n<body><h2>HTTP ERROR 404</h2>\n<p>Problem accessing /job/Ai-Services/xxx/api/json. Reason:\n<pre>    Not Found</pre></p><hr><a href=\"http://eclipse.org/jetty\">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>\n\n</body>\n</html>\n"   at new StatusCodeError (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request-promise-core/lib/errors.js:32:15)   at Request.plumbing.callback (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request-promise-core/lib/plumbing.js:104:33)  at Request.RP$callback [as _callback] (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request-promise-core/lib/plumbing.js:46:31)  at Request.self.callback (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request/request.js:185:22)    at Request.emit (events.js:223:5)   at Request.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request/request.js:1161:10) at Request.emit (events.js:223:5)   at IncomingMessage.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/request/request.js:1083:12) at Object.onceWrapper (events.js:312:28)    at IncomingMessage.emit (events.js:228:7)   at endReadableNT (_stream_readable.js:1185:12)  at processTicksAndRejections (internal/process/task_queues.js:81:21)
console.ts:137 [Extension Host] SyntaxError: Unexpected token u in JSON at position 0   at JSON.parse (<anonymous>) at /home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/out/jenkinsService.js:134:29  at runMicrotasks (<anonymous>)  at processTicksAndRejections (internal/process/task_queues.js:94:5)
console.ts:137 [Extension Host] rejected promise not handled within 1 second: SyntaxError: Unexpected token u in JSON at position 0
t.log @ console.ts:140
$logExtensionHostMessage @ mainThreadConsole.ts:29
_doInvokeHandler @ rpcProtocol.ts:365
_invokeHandler @ rpcProtocol.ts:365
_receiveRequest @ rpcProtocol.ts:306
_receiveOneMessage @ rpcProtocol.ts:174
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:584
fire @ ipc.net.ts:431
_receiveMessage @ ipc.net.ts:764
(anonymous) @ ipc.net.ts:624
fire @ event.ts:584
acceptChunk @ ipc.net.ts:174
(anonymous) @ ipc.net.ts:174
t @ ipc.net.ts:900
emit @ events.js:223
addChunk @ _stream_readable.js:309
readableAddChunk @ _stream_readable.js:290
Readable.push @ _stream_readable.js:224
onStreamRead @ internal/stream_base_commons.js:181
console.ts:137 [Extension Host] stack trace: SyntaxError: Unexpected token u in JSON at position 0  at JSON.parse (<anonymous>) at /home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/out/jenkinsService.js:134:29  at runMicrotasks (<anonymous>)  at processTicksAndRejections (internal/process/task_queues.js:94:5)
t.log @ console.ts:140
$logExtensionHostMessage @ mainThreadConsole.ts:29
_doInvokeHandler @ rpcProtocol.ts:365
_invokeHandler @ rpcProtocol.ts:365
_receiveRequest @ rpcProtocol.ts:306
_receiveOneMessage @ rpcProtocol.ts:174
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:584
fire @ ipc.net.ts:431
_receiveMessage @ ipc.net.ts:764
(anonymous) @ ipc.net.ts:624
fire @ event.ts:584
acceptChunk @ ipc.net.ts:174
(anonymous) @ ipc.net.ts:174
t @ ipc.net.ts:900
emit @ events.js:223
addChunk @ _stream_readable.js:309
readableAddChunk @ _stream_readable.js:290
Readable.push @ _stream_readable.js:224
onStreamRead @ internal/stream_base_commons.js:181
mainThreadExtensionService.ts:65 [[object Object]]Unexpected token u in JSON at position 0
$onExtensionRuntimeError @ host.ts:10
_doInvokeHandler @ rpcProtocol.ts:365
_invokeHandler @ rpcProtocol.ts:365
_receiveRequest @ rpcProtocol.ts:306
_receiveOneMessage @ rpcProtocol.ts:174
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:584
fire @ ipc.net.ts:431
_receiveMessage @ ipc.net.ts:764
(anonymous) @ ipc.net.ts:624
fire @ event.ts:584
acceptChunk @ ipc.net.ts:174
(anonymous) @ ipc.net.ts:174
t @ ipc.net.ts:900
emit @ events.js:223
addChunk @ _stream_readable.js:309
readableAddChunk @ _stream_readable.js:290
Readable.push @ _stream_readable.js:224
onStreamRead @ internal/stream_base_commons.js:181
mainThreadExtensionService.ts:66 SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/out/jenkinsService.js:134
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94)
$onExtensionRuntimeError @ host.ts:10
_doInvokeHandler @ rpcProtocol.ts:365
_invokeHandler @ rpcProtocol.ts:365
_receiveRequest @ rpcProtocol.ts:306
_receiveOneMessage @ rpcProtocol.ts:174
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:584
fire @ ipc.net.ts:431
_receiveMessage @ ipc.net.ts:764
(anonymous) @ ipc.net.ts:624
fire @ event.ts:584
acceptChunk @ ipc.net.ts:174
(anonymous) @ ipc.net.ts:174
t @ ipc.net.ts:900
emit @ events.js:223
addChunk @ _stream_readable.js:309
readableAddChunk @ _stream_readable.js:290
Readable.push @ _stream_readable.js:224
onStreamRead @ internal/stream_base_commons.js:181
console.ts:137 [Extension Host] getJobsFromUrl: 10s
console.ts:137 [Extension Host] getBuilds: 9s
console.ts:137 [Extension Host] getBuilds: 12s

Example of jenkins file

pipeline { 

    agent none    
    stages {         
        stage('Build') {    
            agent { 
                docker { 
                    image 'adoptopenjdk/maven-openjdk8:latest'                    
                    label 'ai-services-docker || SAaaS_Build_BCPNode' // eventualy SAaaS_Build_BCPNode could be removed because we have own build node ai-services-docker
                    args '-v "$HOME"/.m2:/root/.m2'  //to persist maven cache
                    } 
            }             
            steps { 
                echo 'hi'
            }
        }

    }
}

.Jenkins.config.json

{
    "name": "xxx",
    "params": null,
    "folder": "Ai-Services"
}

if I change folder in .Jenkins.config.json to "folder": "Ai-Services/job" Then I get

[Extension Host] Error: jenkins: job.config: job Ai-Services/job//xxx not found at Jenkins.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/jenkins/lib/middleware.js:98:17)    at next (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:311:10) at Jenkins._onResponse (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/jenkins/lib/jenkins.js:156:3)   at next (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:311:10) at IncomingMessage.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:611:7)   at IncomingMessage.emit (events.js:228:7)   at endReadableNT (_stream_readable.js:1185:12)  at processTicksAndRejections (internal/process/task_queues.js:81:21)
console.ts:137 [Extension Host] Error: jenkins: job.config: job Ai-Services/job/xxx not found   at Jenkins.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/jenkins/lib/middleware.js:98:17)    at next (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:311:10) at Jenkins._onResponse (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/jenkins/lib/jenkins.js:156:3)   at next (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:311:10) at IncomingMessage.<anonymous> (/home/vlcvi01/.vscode-server/extensions/tabeyti.jenkins-jack-1.1.1/node_modules/papi/lib/client.js:611:7)   at IncomingMessage.emit (events.js:228:7)   at endReadableNT (_stream_readable.js:1185:12)  at processTicksAndRejections (internal/process/task_queues.js:81:21)
tabeyti commented 3 years ago

Thanks for the additional info @VitekVlcek-Broadcom.

Do you mind sending me what your connection config in settings.json looks like (excluding sensitive info)?

For example:

{
    "name": "My Jenkles",
    "uri": "https://myjennkles.com",
    "username": "myuser",
    "password": "",
    "active": false
},
VitekVlcek-Broadcom commented 3 years ago

user - settings.json

{
    "jenkins-jack.jenkins.connections": [

        {
            "name": "jenkins01",
            "uri": "https://jenkins.acme.net",
            "username": "myuserid",
            "password": "mypassword",
            "active": true
        }
...
tabeyti commented 3 years ago

Hey @VitekVlcek-Broadcom,

Some potentially good news. You latest error may be due to a bug introduced in the 1.1.1 update.

I've put in a fix and created a .vsix extension file I'd like you try. Just unzip the file and follow these instructions on how to install it.

If this fixes things, I will put out an update as soon as a I can.

jenkins-jack-0.0.0.vsix.zip

VitekVlcek-Broadcom commented 3 years ago

It works great. However I have feeling that both 1.1.1 and 0.0.0 and slower compare to 1.1.0, population of side panels with pipelines jobs and nodes takes a lot of time. Thx for support