jenkinsci / configuration-as-code-plugin

Jenkins Configuration as Code Plugin
https://plugins.jenkins.io/configuration-as-code
MIT License
2.69k stars 720 forks source link

Export unit test doesn't include unclassified section #729

Closed timja closed 5 years ago

timja commented 5 years ago

This unit test fails: https://github.com/jenkinsci/azure-keyvault-plugin/blob/51dd43f5c1ee915de6da9c4c4b0a0c9e5f5b4b67/src/test/java/org/jenkinsci/plugins/azurekeyvaultplugin/ConfigAsCodeTest.java#L40

But works when exported manually from the UI The databinding unit test passes for importing the configuration as code yaml

The exported yaml file from the unit test export is:

plugins:
  sites:
  - id: "default"
    url: "http://localhost:59712/update-center.json"
jenkins:
  agentProtocols:
  - "JNLP4-connect"
  - "Ping"
  disableRememberMe: false
  mode: NORMAL
  numExecutors: 2
  primaryView:
    all:
      name: "all"
  quietPeriod: 5
  scmCheckoutRetryCount: 0
  slaveAgentPort: 0
  views:
  - all:
      name: "all"
credentials:
  system:
    domainCredentials:
    - credentials:
      - azure:
          azureEnvironmentName: "Azure"
          clientId: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
          clientSecret: "****"
          description: "An azure service principal"
          id: "service-principal"
          scope: GLOBAL
          subscriptionId: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
          tenant: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
tool:
  jdk:
    installations:
    - home: "/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre"
      name: "default"

It's missing the azureKeyVault section:

unclassified:
  azureKeyVault:
    credentialID: "sandbox-sp"
    keyVaultURL: "https://a-vault.vault.azure.net"

Example exported from UI:

plugins:
  sites:
  - id: "default"
    url: "https://updates.jenkins.io/update-center.json"
jenkins:
  agentProtocols:
  - "JNLP4-connect"
  - "Ping"
  disableRememberMe: false
  mode: NORMAL
  numExecutors: 2
  primaryView:
    all:
      name: "all"
  quietPeriod: 5
  scmCheckoutRetryCount: 0
  slaveAgentPort: 0
  views:
  - all:
      name: "all"
credentials:
  system:
    domainCredentials:
    - credentials:
      - azure:
          azureEnvironmentName: "Azure"
          clientId: "***"
          clientSecret: "*****"
          description: "Sandbox SP"
          id: "sandbox-sp"
          scope: GLOBAL
          subscriptionId: "***"
          tenant: "***"
      - vaultTokenCredential:
          description: "hashi secret"
          id: "abcd-efg"
          scope: GLOBAL
          token: "asd;asjdsa;"
unclassified:
  azureKeyVault:
    credentialID: "sandbox-sp"
    keyVaultURL: "https://a-vault.vault.azure.net"
tool:
  git:
    installations:
    - home: "git"
      name: "Default"
  jdk:
    defaultProperties:
    - installSource:
        installers:
        - jdkInstaller:
            acceptLicense: false

Anyone got any ideas? Something I'm doing that's wrong? Or is this a bug, it's weird that if I export from the UI it works though

Startup log:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/timja/.m2/repository/org/slf4j/slf4j-simple/1.7.5/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/timja/.m2/repository/org/slf4j/slf4j-jdk14/1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO org.eclipse.jetty.util.log - Logging initialized @1949ms to org.eclipse.jetty.util.log.Slf4jLog
=== Starting export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)
   0.096 [id=12]    INFO    o.jvnet.hudson.test.WarExploder#explode: Picking up existing exploded jenkins.war at /Users/timja/projects/azure-keyvault-plugin/target/jenkins-for-test
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.Server - jetty-9.4.5.v20170502
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.webapp.StandardDescriptorProcessor - NO JSP Support for /jenkins, did not find org.eclipse.jetty.jsp.JettyJspServlet
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - DefaultSessionIdManager workerName=node0
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - No SessionScavenger set, using defaults
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - Scavenging every 660000ms
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@fee5696{/jenkins,file:///Users/timja/projects/azure-keyvault-plugin/target/jenkins-for-test/,AVAILABLE}{/Users/timja/projects/azure-keyvault-plugin/target/jenkins-for-test}
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@62fbe8c5{HTTP/1.1,[http/1.1]}{localhost:59709}
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.Server - Started @5024ms
   0.846 [id=12]    INFO    o.jvnet.hudson.test.JenkinsRule#createWebServer: Running on http://localhost:59709/jenkins/
   3.178 [id=22]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
   3.205 [id=24]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
   8.016 [id=25]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
   8.026 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
   8.028 [id=20]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
  10.343 [id=23]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
  11.036 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
  11.059 [id=43]    INFO    hudson.UDPBroadcastThread#run: Cannot listen to UDP port 33,848, skipping: java.net.SocketException: Can't assign requested address
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.Server - jetty-9.4.5.v20170502
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - DefaultSessionIdManager workerName=node0
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - No SessionScavenger set, using defaults
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - Scavenging every 660000ms
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@255b9b51{/,null,AVAILABLE}
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@29f87f44{HTTP/1.1,[http/1.1]}{0.0.0.0:59712}
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.Server - Started @15320ms
  11.461 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.scope = GLOBAL
  11.462 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.id = service-principal
  11.463 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.description = An azure service principal
  11.464 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.subscriptionId = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  11.464 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.clientId = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  11.464 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.clientSecret = not a real secret
  11.530 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.microsoft.azure.util.AzureCredentials@6b5dfb16.azureEnvironmentName = Azure
  11.531 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.microsoft.azure.util.AzureCredentials@6b5dfb16.tenant = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  11.533 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.cloudbees.plugins.credentials.domains.DomainCredentials.credentials = [{azure={}}]
  12.130 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.scope = GLOBAL
  12.130 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.id = service-principal
  12.131 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.description = An azure service principal
  12.131 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.subscriptionId = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  12.133 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.clientId = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  12.134 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.microsoft.azure.util.AzureCredentials.clientSecret = not a real secret
  12.136 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.microsoft.azure.util.AzureCredentials@6b5dfb16.azureEnvironmentName = Azure
  12.136 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.microsoft.azure.util.AzureCredentials@6b5dfb16.tenant = d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc
  12.136 [id=12]    INFO    i.j.p.c.i.c.DataBoundConfigurator#tryConstructor: Setting class com.cloudbees.plugins.credentials.domains.DomainCredentials.credentials = [{azure={}}]
  12.139 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.cloudbees.plugins.credentials.SystemCredentialsProvider@396d390e.domainCredentials = [com.cloudbees.plugins.credentials.domains.DomainCredentials@61c57402]
  12.174 [id=12]    WARNING o.j.r.u.AnonymousClassWarnings#warn: Attempt to (de-)serialize anonymous class com.cloudbees.plugins.credentials.CredentialsScope$2 in file:/Users/timja/.m2/repository/org/jenkins-ci/plugins/credentials/2.1.14/credentials-2.1.14.jar; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
  12.184 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting com.cloudbees.plugins.credentials.GlobalCredentialsConfiguration@23b73e75.system = com.cloudbees.plugins.credentials.SystemCredentialsProvider@396d390e
  12.864 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting org.jenkinsci.plugins.azurekeyvaultplugin.AzureKeyVaultGlobalConfiguration@44db0d51.keyVaultURL = https://not-a-real-vault.vault.azure.net
  12.865 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting org.jenkinsci.plugins.azurekeyvaultplugin.AzureKeyVaultGlobalConfiguration@44db0d51.credentialID = service-principal
  12.872 [id=12]    INFO    i.jenkins.plugins.casc.Attribute#setValue: Setting jenkins.model.GlobalConfigurationCategory$Unclassified@29ea201e.azureKeyVault = org.jenkinsci.plugins.azurekeyvaultplugin.AzureKeyVaultGlobalConfiguration@44db0d51
plugins:
  sites:
  - id: "default"
    url: "http://localhost:59712/update-center.json"
jenkins:
  agentProtocols:
  - "JNLP4-connect"
  - "Ping"
  disableRememberMe: false
  mode: NORMAL
  numExecutors: 2
  primaryView:
    all:
      name: "all"
  quietPeriod: 5
  scmCheckoutRetryCount: 0
  slaveAgentPort: 0
  views:
  - all:
      name: "all"
credentials:
  system:
    domainCredentials:
    - credentials:
      - azure:
          azureEnvironmentName: "Azure"
          clientId: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
          clientSecret: "****"
          description: "An azure service principal"
          id: "service-principal"
          scope: GLOBAL
          subscriptionId: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
          tenant: "d63d9de6-5f7a-48c1-ac1d-e90d4f5e5dcc"
tool:
  jdk:
    installations:
    - home: "/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre"
      name: "default"

[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.AbstractConnector - Stopped ServerConnector@62fbe8c5{HTTP/1.1,[http/1.1]}{localhost:0}
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.session - Stopped scavenging
[Executing export_configuration(org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest)] INFO org.eclipse.jetty.server.handler.ContextHandler - Stopped o.e.j.w.WebAppContext@fee5696{/jenkins,file:///Users/timja/projects/azure-keyvault-plugin/target/jenkins-for-test/,UNAVAILABLE}{/Users/timja/projects/azure-keyvault-plugin/target/jenkins-for-test}
  23.961 [id=12]    INFO    jenkins.model.Jenkins#cleanUp: Stopping Jenkins
 104.449 [id=12]    INFO    jenkins.model.Jenkins#cleanUp: Jenkins stopped

java.lang.AssertionError: blah

    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at org.jenkinsci.plugins.azurekeyvaultplugin.ConfigAsCodeTest.export_configuration(ConfigAsCodeTest.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:553)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.lang.Thread.run(Thread.java:748)

Process finished with exit code 255
timja commented 5 years ago

If anyone has any ideas on this help appreciated, have debugged through it a bit :(

jetersen commented 5 years ago

Doesn't make sense to validate a full export() take the approach done in plugin module and in metrics plugn: https://github.com/jenkinsci/metrics-plugin/pull/43

timja commented 5 years ago

Tried that here: https://github.com/jenkinsci/azure-keyvault-plugin/pull/15

Didn't work 😢 I wonder if it's anything to do with it being a global configuration class and its not being picked up.

It's weird though because it does actually work, I just can't get a test that contains the config