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

editing the existing declarative jenkinsfile in pipeline editor

    • Blue Ocean 1.4 - beta 3, Blue Ocean 1.5 - beta 1

      Hello,

      I have created jenkinsfile ( declarative pipeline) and no issues with the stages /build is running- but I have not created this via the blue ocean editor.

      But I want to edit it via the blue ocean editor and I cannot do it.
      I can see the pipeline in the blue ocean and when I click on edit option - I see a blank screen.

      so is this not possible to edit the declarative pipeline ( which is not created in editor ) in blue ocean pipeline editor?

      Regards,
      Ashwin

          [JENKINS-48119] editing the existing declarative jenkinsfile in pipeline editor

          Ashwin Y added a comment -

          Hello James,

          I have added our github organization and our repo consists of Jenkinsfile . Not directly used the multibranch or the pipeline type for declarative pipeline

          Ashwin Y added a comment - Hello James, I have added our github organization and our repo consists of Jenkinsfile . Not directly used the multibranch or the pipeline type for declarative pipeline

          Karl Shultz added a comment -

          ashsy_009 - a few questions.

          1. Which style of Pipeline syntax are you using - Declarative, or Scripted? The way to tell is, if your Pipeline code is wrapped with

          pipeline {
              // Pipeline setup, stages, and other stuff here
          }
          

          Then you're using Declarative. But if your pipeline does not have the {{pipeline { ... }}} block wrapped around it, you're using Scripted pipeline. The reason I ask is, the only style of Pipeline supported by the editor is Declarative.

          2. If you're using Declarative, are you able to provide us with a sample Jenkinsfile to try and recreate the issue with? If it's only a Jenkinsfile, and has no need for external libraries or anything else, we might be able to recreate the issue with only the Jenkinsfile. If your repo is public, we could fork it and try to recreate the issue that way.

          3. Is your Jenkinsfile stored somewhere other than the root directory of your repository?

          Karl Shultz added a comment - ashsy_009 - a few questions. 1. Which style of Pipeline syntax are you using - Declarative, or Scripted? The way to tell is, if your Pipeline code is wrapped with pipeline { // Pipeline setup, stages, and other stuff here } Then you're using Declarative. But if your pipeline does not have the {{pipeline { ... }}} block wrapped around it, you're using Scripted pipeline. The reason I ask is, the only style of Pipeline supported by the editor is Declarative. 2. If you're using Declarative, are you able to provide us with a sample Jenkinsfile to try and recreate the issue with? If it's only a Jenkinsfile, and has no need for external libraries or anything else, we might be able to recreate the issue with only the Jenkinsfile. If your repo is public, we could fork it and try to recreate the issue that way. 3. Is your Jenkinsfile stored somewhere other than the root directory of your repository?

          Michael Neale added a comment -

          Need to get a har/console error log for this. 

          Michael Neale added a comment - Need to get a har/console error log for this. 

          Michael Neale added a comment -

          open if there is more information

          Michael Neale added a comment - open if there is more information

          Ashwin Y added a comment -

          Hello,

          My concern is :
          1. I migrated scripted syntx to declarative syntax Jenkinsfile using shared library in the jenkinsfile and I have not created this jenkinsfile via the pipeline editor/blue-ocean editor.
          2 . I am able to create a new jenkinsfile via the blue ocean editor and currently shared libraries not supported correct? But I want to edit the existing or migrated Jenkinsfile via blue-ocean editor.

          Is this possible?

          Regards,
          Ashwin

          Ashwin Y added a comment - Hello, My concern is : 1. I migrated scripted syntx to declarative syntax Jenkinsfile using shared library in the jenkinsfile and I have not created this jenkinsfile via the pipeline editor/blue-ocean editor. 2 . I am able to create a new jenkinsfile via the blue ocean editor and currently shared libraries not supported correct? But I want to edit the existing or migrated Jenkinsfile via blue-ocean editor. Is this possible? Regards, Ashwin

          Vivek Pandey added a comment -

          Hi ashsy_009

          Please provide declarative script that reproduces this issue. Without that we do not know how to reproduce it.

           

          Vivek Pandey added a comment - Hi ashsy_009 ,  Please provide declarative script that reproduces this issue. Without that we do not know how to reproduce it.  

          Vivek Pandey added a comment -

          We don't know how to reproduce it, please reopen with reproducible test case.

          Vivek Pandey added a comment - We don't know how to reproduce it, please reopen with reproducible test case.

          Pino Alu added a comment -

          Same issue for me as well.  We are using Bitbucket repo.  My jenkinsfile is attached and we cannot edit Jenkinsfile using Blue Ocean editor.Jenkinsfile

          Pino Alu added a comment - Same issue for me as well.  We are using Bitbucket repo.  My jenkinsfile is attached and we cannot edit Jenkinsfile using Blue Ocean editor. Jenkinsfile

          Karl Shultz added a comment -

          TLDR version:
          pino_alu, I figured out how to fix your Pipeline up. Try wrapping that withSonarQube thing inside of a script block. That fixed it up for me. Note that I am running on bleeding edge Blue Ocean 1.5-SNAPSHOT code, so, your mileage may vary. But I was at least able to see it fail, and figure out how to fix it. Might work for you too.

          Long version:
          I'm taking a look at this now, and can confirm pino_alu's report that his provided Jenkinsfile doesn't show up in the editor, even though it is seen by the Declarative validator as a valid pipeline. What I did was, create a brand new repo on a Bitbucket server, and upload this Jenkinsfile exactly to its master branch. Then I created a new pipeline in Blue Ocean using that repo as its basis. Note that I did not expect the build of this pipeline to succeed - Pino has different maven and jdk tool labels, so I didn't expect it to just work like magic. And that part actually worked just fine - Blue Ocean (and the command line Jenkinsfile linter, for that matter) both told me what was wrong.

          ✔ ~/Bitbucket/jenkins-48119 [master L|…1] 
          15:43 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile
          Errors encountered validating Jenkinsfile:
          WorkflowScript: 47: Tool type "maven" does not have an install of "Maven_3.0.5" configured - did you mean "null"? @ line 47, column 11.
                 maven 'Maven_3.0.5'
                       ^
          
          WorkflowScript: 48: Tool type "jdk" does not have an install of "jdk1.8" configured - did you mean "null"? @ line 48, column 9.
                 jdk 'jdk1.8'
                     ^
          
          

          Interestingly, when I deleted the tools block, and commented out the withSonarQubeEnv block, things worked:

          // withSonarQubeEnv('AzureSonarServer') {
              // sh 'mvn clean test package sonar:sonar -Dsonar.host.url=http://sonarsrv.abc.com:9000/sonar -Dsonar.login=31b8fe1ce4d179e11af2154a7b594dbaf21aa46d'
          // }
          

          So we know that the combination of deleting that tools block AND deleting the withSonarQubeEnv block, got the editor to behave. Time for some process of elimination. I added JDK and Maven installs to my instance, matching the names in Pino's Jenkinsfile. This got me past Declarative complaining about tools not being valid, so, that's great! And it worked. It loaded into the editor and everything.

          Next step was to un-comment the withSonarQubeEnv block so that would be processed. Basically we were back where we started, only this time, with matching Maven and JDK listings in Global Tool Config. And we were back to being broken, even though the Jenkinsfile shows as being okay:

          ✔ ~/Bitbucket/jenkins-48119 [master|✔] 
          16:24 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile
          Jenkinsfile successfully validated.
          

          On a whim, I decided to wrap Pino's withSonarQubeEnv thing in a script block. Like this (pardon the messy formatting, I'm trying to change as little as I can here):

              script {
                  withSonarQubeEnv('AzureSonarServer') {
          		sh 'mvn clean test package sonar:sonar -Dsonar.host.url=http://sonarsrv.abc.com:9000/sonar -Dsonar.login=31b8fe1ce4d179e11af2154a7b594dbaf21aa46d'
          				}
                }
          

          Now let's revalidate with the CLI linter:

          ✔ ~/Bitbucket/jenkins-48119 [master|✔] 
          16:29 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile
          Jenkinsfile successfully validated.
          

          I rescaned the MBP project, and launched Blue Ocean, and...ta-da! It works!

          It looks like the Declarative validator isn't complaining about that withSonarQube thing, and maybe it should be, since wrapping it inside a script block looks to have fixed everything right up. I'd be curious to see if abayer has any thoughts on that.

          pino_alu (and others) - just keep in mind that once you start putting things in script blocks, the Editor has very little control over what's in there. Those blocks are meant for when you need to escape the guardrailed environment of Declarative, and do something more elaborate. Validating non-Declarative code inside of an editor built entirely for Declarative wouldn't be realistic. But we can at least make sure it doesn't break.

          I hope that's some help?

          Karl Shultz added a comment - TLDR version : pino_alu , I figured out how to fix your Pipeline up. Try wrapping that withSonarQube thing inside of a script block. That fixed it up for me. Note that I am running on bleeding edge Blue Ocean 1.5-SNAPSHOT code, so, your mileage may vary. But I was at least able to see it fail, and figure out how to fix it. Might work for you too. Long version : I'm taking a look at this now, and can confirm pino_alu 's report that his provided Jenkinsfile doesn't show up in the editor, even though it is seen by the Declarative validator as a valid pipeline. What I did was, create a brand new repo on a Bitbucket server, and upload this Jenkinsfile exactly to its master branch. Then I created a new pipeline in Blue Ocean using that repo as its basis. Note that I did not expect the build of this pipeline to succeed - Pino has different maven and jdk tool labels, so I didn't expect it to just work like magic. And that part actually worked just fine - Blue Ocean (and the command line Jenkinsfile linter, for that matter) both told me what was wrong. ✔ ~/Bitbucket/jenkins-48119 [master L|…1] 15:43 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile Errors encountered validating Jenkinsfile: WorkflowScript: 47: Tool type "maven" does not have an install of "Maven_3.0.5" configured - did you mean "null"? @ line 47, column 11. maven 'Maven_3.0.5' ^ WorkflowScript: 48: Tool type "jdk" does not have an install of "jdk1.8" configured - did you mean "null"? @ line 48, column 9. jdk 'jdk1.8' ^ Interestingly, when I deleted the tools block, and commented out the withSonarQubeEnv block, things worked: // withSonarQubeEnv('AzureSonarServer') { // sh 'mvn clean test package sonar:sonar -Dsonar.host.url=http://sonarsrv.abc.com:9000/sonar -Dsonar.login=31b8fe1ce4d179e11af2154a7b594dbaf21aa46d' // } So we know that the combination of deleting that tools block AND deleting the withSonarQubeEnv block, got the editor to behave. Time for some process of elimination. I added JDK and Maven installs to my instance, matching the names in Pino's Jenkinsfile. This got me past Declarative complaining about tools not being valid, so, that's great! And it worked. It loaded into the editor and everything. Next step was to un-comment the withSonarQubeEnv block so that would be processed. Basically we were back where we started, only this time, with matching Maven and JDK listings in Global Tool Config. And we were back to being broken, even though the Jenkinsfile shows as being okay: ✔ ~/Bitbucket/jenkins-48119 [master|✔] 16:24 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile Jenkinsfile successfully validated. On a whim, I decided to wrap Pino's withSonarQubeEnv thing in a script block. Like this (pardon the messy formatting, I'm trying to change as little as I can here): script { withSonarQubeEnv('AzureSonarServer') { sh 'mvn clean test package sonar:sonar -Dsonar.host.url=http://sonarsrv.abc.com:9000/sonar -Dsonar.login=31b8fe1ce4d179e11af2154a7b594dbaf21aa46d' } } Now let's revalidate with the CLI linter: ✔ ~/Bitbucket/jenkins-48119 [master|✔] 16:29 $ java -jar ~/bin/jenkins-cli.jar -auth admin:admin -s http://127.0.0.1:8080/jenkins declarative-linter < Jenkinsfile Jenkinsfile successfully validated. I rescaned the MBP project, and launched Blue Ocean, and...ta-da! It works! It looks like the Declarative validator isn't complaining about that withSonarQube thing, and maybe it should be, since wrapping it inside a script block looks to have fixed everything right up. I'd be curious to see if abayer has any thoughts on that. pino_alu (and others) - just keep in mind that once you start putting things in script blocks, the Editor has very little control over what's in there. Those blocks are meant for when you need to escape the guardrailed environment of Declarative, and do something more elaborate. Validating non-Declarative code inside of an editor built entirely for Declarative wouldn't be realistic. But we can at least make sure it doesn't break. I hope that's some help?

          Pino Alu added a comment -

          That worked.  Thank You!

          Pino Alu added a comment - That worked.  Thank You!

            vivek Vivek Pandey
            ashsy_009 Ashwin Y
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: