Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to reference relative file for "jobs:" configuration #695

Closed
MartinSGill opened this issue Jan 8, 2019 · 6 comments
Closed

Ability to reference relative file for "jobs:" configuration #695

MartinSGill opened this issue Jan 8, 2019 · 6 comments

Comments

@MartinSGill
Copy link

MartinSGill commented Jan 8, 2019

Current jobs: looks like this:

jobs:
  - script: >
      multibranchPipelineJob('configuration-as-code') {
          branchSources {
              git {
                  id = 'configuration-as-code'
                  remote('https://github.com/jenkinsci/configuration-as-code-plugin.git')
              }
          }
      }

I would much prefer to have it reference files.

jobs:
   files:
      - job1.groovy
      - ./other/job2.groovy

I my experience, no seed job is quite as simple as the example. When attempting to migrate an existing server to JCASC one of my biggest stumbling blocks was converting/escaping/updating existing jobdsl. If jcasc supported loading of groovy files then I could almost just copy existing jobdsl and use it with almost zero effort on my part.

The advantage of this is that:

  • remove the need for any escaping
  • can use a groovy aware editor for jobdsl
  • can easily test jobdsl in Jenkins or with other tools (without need for unescape/escape cycle
  • greatly simplify migration to JCASC by allowing easy re-use of existing scripts.

Jenkins version: 2.156
Plugin version: 1.4
OS: docker:alpine

@muety
Copy link
Contributor

muety commented Feb 4, 2019

I'd love to have this! Any news on this issue?

@Lorquas
Copy link

Lorquas commented Feb 11, 2019

try:

jobs:
  - file: /some/path/jenkins/can/get/to/file.groovy
  - file: /some/other/file.groovy

*EDIT: the file has to be avaialbe to the jenkins master, I put it in $JENKINS_HOME. You can also use - url: http://some/file.groovy. Found this by reading the source in support/src/main/java/io/jenkins/plugins/casc/support/jobdsl; This could probably be documented in the jobs section of the demos.

@MartinSGill
Copy link
Author

@Lorquas nicely found! Did you see if it accepts relative paths, or only absolute?

@jetersen
Copy link
Member

jetersen commented May 3, 2019

it supports relative files @MartinSGill

@jetersen jetersen closed this as completed May 5, 2019
@EricSalemi
Copy link

EricSalemi commented Jun 30, 2020

@jetersen

Where is this documented?
How are relative paths resolved?

If I declare file: jobs/myjob.groovy and place the file in /var/jenkins_home/jobs/myjob.groovy then I get this error:

jenkins_1      | java.io.FileNotFoundException: File 'jobs/myjob.groovy' does not exist
jenkins_1      | 	at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:297)
jenkins_1      | 	at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1805)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.FromFileScriptSource.getScript(FromFileScriptSource.java:23)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.SeedJobConfigurator.lambda$getScriptFromSource$becf3cba$1(SeedJobConfigurator.java:125)
jenkins_1      | 	at io.vavr.CheckedFunction0.lambda$unchecked$52349c75$1(CheckedFunction0.java:247)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.SeedJobConfigurator.getScriptFromSource(SeedJobConfigurator.java:125)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.SeedJobConfigurator.lambda$configure$2(SeedJobConfigurator.java:69)
jenkins_1      | 	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
jenkins_1      | 	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
jenkins_1      | 	at java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:419)
jenkins_1      | 	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647)
jenkins_1      | 	at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:272)
jenkins_1      | 	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
jenkins_1      | 	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
jenkins_1      | 	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
jenkins_1      | 	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:546)
jenkins_1      | 	at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
jenkins_1      | 	at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:505)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.SeedJobConfigurator.configure(SeedJobConfigurator.java:71)
jenkins_1      | 	at javaposse.jobdsl.plugin.casc.SeedJobConfigurator.configure(SeedJobConfigurator.java:32)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$configureWith$6(ConfigurationAsCode.java:747)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:691)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:747)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:616)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:298)
jenkins_1      | 	at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:290)

@EricSalemi
Copy link

EricSalemi commented Jun 30, 2020

Seems to be documented here:

https://github.com/jenkinsci/job-dsl-plugin/wiki/JCasC

Does not work me when using the jenkins/jenkins:2.235.1 Docker image.

Apparently other people see this issue in #1145 (comment) (closed issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants