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

Support seed job creation in Configuration as Code, updated #1173

Merged
merged 5 commits into from
Apr 26, 2019
Merged

Support seed job creation in Configuration as Code, updated #1173

merged 5 commits into from
Apr 26, 2019

Conversation

jetersen
Copy link
Member

It is using a released version and the changes that have happened to the configurator in the meantime.
SeedJob configurator now has access to JCasC secrets.

ndeloof and others added 2 commits April 25, 2019 05:49
…-as-code managed jenkins master

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Copy link
Member

@daspilker daspilker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please remove any noise from the code as mentioned in my comments. Can we close #1142?


@Override
public GeneratedItems[] check(CNode config, ConfigurationContext context) throws ConfiguratorException {
// Any way to dry-run a job-dsl script ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not yet.

import io.jenkins.plugins.casc.model.CNode;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all author tags.

@jetersen
Copy link
Member Author

jetersen commented Apr 25, 2019

@daspilker Done would be great to get this into job dsl 🤞

as demonstrated by Matrix auth plugin the configurators can co-exist as long as the ordinal is higher than what is than what configuration-as-code-support-plugin ordinal is 😅

jenkinsci/matrix-auth-plugin#48

@jetersen
Copy link
Member Author

We just merged jenkinsci/configuration-as-code-plugin#845
I will see if I can create a similar PR for removing job dsl from jcasc-support plugin

@timja
Copy link
Member

timja commented Apr 25, 2019

There's no incremental build here @Casz

@jetersen
Copy link
Member Author

I know, will have to deploy a snapshot 😆

@daspilker
Copy link
Member

@Casz Can I release this change anytime or do you need to remove Job DSL from jcasc-support plugin first?

@jetersen
Copy link
Member Author

you can release it anytime @daspilker 🙌 it was just if you wanted proof that it works since we have some integrations tests.

The PR would be very similar to jenkinsci/configuration-as-code-plugin#845

@jetersen
Copy link
Member Author

@daspilker let me get the integration tests working... 😓 Seems we might have trouble

@daspilker
Copy link
Member

@Casz I did a manual test. I never used CasC before, I wanted to see how it works. Quite nice actually 👍 . This Job DSL section does not appear in the reference. Is that expected?

@jetersen
Copy link
Member Author

jetersen commented Apr 25, 2019

Oh I just forgot to deploy all the snapshots... I only deployed the plugin not core...

@jetersen
Copy link
Member Author

That is expected, we could add some sort of support for exporting like storing the sources. Shouldn't be too difficult 😓

@daspilker
Copy link
Member

What do you mean by storing the sources? Must that be done on the CasC side? Will that be available soon?

I would also be fine with adding a wiki page with some examples that we can point to. https://github.com/jenkinsci/job-dsl-plugin/tree/master/docs will be pushed to the wiki on every Job DSL release. So you could add a short page to this PR. Maybe you have some existing docs from the support plugin?

@timja
Copy link
Member

timja commented Apr 25, 2019

Existing docs are here:
https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos/jobs

Seems retrieving from a url or file is undocumented there, it only has inline

@jetersen
Copy link
Member Author

jetersen commented Apr 25, 2019

What do you mean by storing the sources? Must that be done on the CasC side? Will that be available soon?

The configurator just has to describe the sources so it can be exported.
Something we can fix in this PR.

@jetersen
Copy link
Member Author

jetersen commented Apr 25, 2019

@timja, I can't for the life of me figure out how to access the ScriptSource instances and describe them.

Unless you have some ideas let's skip the export.

I'll add some docs

@daspilker daspilker merged commit f52cda2 into jenkinsci:master Apr 26, 2019
@jetersen
Copy link
Member Author

🎉

@linux-samurai
Copy link

The release yesterday broke all of our jobs that are using some custom code we wrote in a shared-pipeline-library. I can provide more details about the custom code if needed, but the error message from the jenkins master is here. Jobs were working up until jenkins master ran auto-updates and pulled this new version down (from 1.72 to 1.73). Please advise.

WARNING: Failed to instantiate Key[type=javaposse.jobdsl.plugin.casc.FromFileScriptSource$DescriptorImpl, annotation=[none]]; skipping this component
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.NoClassDefFoundError: javaposse/jobdsl/plugin/casc/FromFileScriptSource
  at javaposse.jobdsl.plugin.casc.FromFileScriptSource$DescriptorImpl.<init>(FromFileScriptSource.java:28)

Caused by: java.lang.NoClassDefFoundError: javaposse/jobdsl/plugin/casc/FromFileScriptSource

com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
        ... 54 more

@jetersen
Copy link
Member Author

jetersen commented Apr 28, 2019

Not sure whether you're actually using JCasC or not.

if you're using JCasC you should define your shared libraries inside JCasC.
So JobDSL can access your shared library code I guess.

You seem to have left out the context of where this error message appeared @linux-samurai
Inside Jenkins startup? When builds are run? Somewhere else.

Do you have JCasC installed or not?
https://github.com/jenkinsci/configuration-as-code-plugin (the plugin should be optional, you do not need to install it)

@linux-samurai
Copy link

linux-samurai commented Apr 28, 2019

@Casz I did not write our shared library code, and still getting up to speed on Groovy coding, so please bear with me. We are not using the 'configuration as code' plugin, but do a lot of the similar functionality within our shared library that the configuration as code plugin looks to be doing.

An example of one of our Jenkinsfiles is as follows, which loads the shared library:

@Library('company-pipeline-lib') _
archetype('GitOrganizationNameRedacted/jenkins-repository-name-redacted') {
config_select = [ applications: params.deploy_application ]
 }

We then have an 'archetype.groovy' in our shared library that takes the input and pulls that declarative pipeline code and injects the 'config_select'. We have a lot of custom DSL methods we wrote that allow us to extend the declarative pipeline a lot, for example we have a 'define' custom method that will take just about any input (string, boolean, key/value pair, array, etc). So this release of job-dsl plugin, and from the error, this specific PR, broke every job we have where this job-dsl-plugin is installed and where we are using our custom DSL methods in our shared library. We have downgraded to 1.72 to get unblocked, but I would like to help flesh out what the root cause is (in our code and how should we improve it or improvements or plugin code improvements) and help improve the code in general, because I wouldn't want us to be locked at this version forever.

If you could let me know if there is something specific I can look for in our shared library code I can circle back.

here is another example of a custom method that was written by the original author, in case it helps:```

@NonCPS
def getBuild(jobName, buildId) {
Jenkins.get().getItemByFullName(jobName)?.getBuild(buildId)
}




@linux-samurai
Copy link

@Casz Sorry, I want to explicitly answer your questions, in case they were not laid out fully in my response earlier.

  1. We are not using the config-as-code plugin.
  2. This only affects systems where we have job-dsl plugin installed.
  3. For now we have downgraded job-dsl plugin to 1.72.
  4. The error was being thrown in a part of the code where we are calling our 'gcloud' custom DSL method.

(job code)

 gcloud 'app deploy', app_yaml, version: appVersion, transform: { it.versions?.first() }

In the shared library, the gcloud.groovy file is a bit lengthy, but here is what we are importing. I'd need to review the code a bit more, and get approval to share it. Initial review doesn't have any glaring sensitivity concerns.

import groovy.json.*
import util.*

@timja
Copy link
Member

timja commented Apr 28, 2019

Sounds like an optional plugin dependency issue?

@jetersen
Copy link
Member Author

Nah, sounds we have duplicate symbols:

@daspilker
Copy link
Member

This has been reported as JENKINS-57218.

Shouldn't symbols have their descriptor type as namespace? Why would the Pipeline DSL pick the FromFileScriptSource in this case? Isn't this a Pipeline problem?

@timja
Copy link
Member

timja commented Apr 30, 2019

Would the easiest fix be to rename fromFileScriptSource symbol to be something like?:

filePath

or

fileLocation
``

@jetersen
Copy link
Member Author

or jobdslFile to avoid conflicts all together

@jetersen
Copy link
Member Author

I agree @daspilker it is a problem in the pipeline. It has been reported several times that Symbol lacks more control.
CC @abayer

@jetersen jetersen deleted the casc branch April 30, 2019 09:58
@michelzanini
Copy link

This has broke our builds also. It fails in startup but also on pipeline executions.
I do not have JCasC installed.

@jetersen
Copy link
Member Author

jetersen commented May 5, 2019

It seems the fix was: #1175 and jenkinsci/structs-plugin#45
Sorry for not marking it optional in this PR completely forgot 😆
Lucky we caught a null pointer in structs plugin 🙌
@linux-samurai @michelzanini hopefully v1.74 should fix it.

@jetersen
Copy link
Member Author

jetersen commented May 24, 2020

FYI jenkinsci/configuration-as-code-plugin#1394 which is released in v1.41 should fix any ordering to the root elements so the job dsl seed job should load last.

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