Re: How to use containerTemplates in declarative kubernetes agent definition

2018-09-10 Thread Matt Buckland
Thanks again Carlos. Unfortunately that syntax doesn't seem to work. I 
have this:


  environment {
IMAGE_TAG   = "${env.IMAGE_TAG}"
JOB_NAME= "${env.JOB_NAME}"
AGENT_IMAGE_TAG = "${env.AGENT_IMAGE_TAG}"
ACCOUNT_ID  = "${env.ACCOUNT_ID}"
  }
  agent {
kubernetes {
  label "${JOB_NAME}"
  inheritFrom 'default'
  containerTemplates {
containerTemplate {
  name 'jnlp'
  image 
'${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}'

  resourceRequestCpu '200m'
  resourceLimitCpu '1'
  resourceRequestMemory '256Mi'
  resourceLimitMemory '1Gi'
}
  }
}


but I get this when I try to run the pipeline. I think maybe generating 
a static yaml is better.



[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException: must specify $class with an 
implementation of interface java.util.List
	at 
org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:474)
	at 
org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:401)
	at 
org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:360)
	at 
org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:283)
	at 
org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescriptor.newInstance(WithScriptDescriptor.java:74)
	at 
org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor.instanceForDescriptor(DeclarativeAgentDescriptor.java:159)
	at 
org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor$instanceForDescriptor$2.call(Unknown 
Source)
	at 
org.jenkinsci.plugins.pipeline.modeldefinition.model.Agent.getDeclarativeAgent(Agent.groovy:81)

at sun.reflect.GeneratedMethodAccessor968.invoke(Unknown Source)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at 
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at 
com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
Caused: java.lang.IllegalArgumentException: Could not instantiate 
{label=Redhat_SSO_Deploy, inheritFrom=default, 
containerTemplates={containerTemplate={name=jnlp, 
image=${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}, 
resourceRequestCpu=200m, resourceLimitCpu=1, 
resourceRequestMemory=256Mi, resourceLimitMemory=1Gi}}} for 
KubernetesDeclarativeAgent(activeDeadlineSeconds?: int, cloud?: String, 
containerTemplate?: ContainerTemplate(name?: String, image?: String, 
alwaysPullImage?: boolean, args?: String, command?: String, envVars?: 
TemplateEnvVar{ContainerEnvVar(key: String, value: String) | 
KeyValueEnvVar(key: String, value: String) | PodEnvVar(key: String, 
value: String) | SecretEnvVar(key: String, secretName: String, 
secretKey: String)}[], livenessProbe?: ContainerLivenessProbe(execArgs: 
String, timeoutSeconds: int, initialDelaySeconds: int, failureThreshold: 
int, periodSeconds: int, successThreshold: int), ports?: 
PortMapping(name?: String, containerPort?: int, hostPort?: int)[], 
privileged?: boolean, resourceLimitCpu?: String, resourceLimitMemory?: 
String, resourceRequestCpu?: String, resourceRequestMemory?: String, 
shell?: String, ttyEnabled?: boolean, workingDir?: String), 
containerTemplates?: ContainerTemplate(name?: String, image?: String, 
alwaysPullImage?: boolean, args?: String, command?: String, envVars?: 
TemplateEnvVar{ContainerEnvVar(key: String, value: String) | 
KeyValueEnvVar(key: String, value: String) | PodEnvVar(key: String, 
value: String) | SecretEnvVar(key: String, secretName: String, 
secretKey: String)}[], livenessProbe?: ContainerLivenessProbe(execArgs: 
String, timeoutSeconds: int, initialDelaySeconds: int, failureThreshold: 
int, periodSeconds: int, successThreshold: int), ports?: 
PortMapping(name?: String, containerPort?: int, hostPort?: int)[], 
privileged?: boolean, resourceLimitCpu?: String, resourceLimitMemory?: 
String, resourceRequestCpu?: String, resourceRequestMemory?: String, 
shell?: String, ttyEnabled?: boolean, workingDir?: String)[], 
defaultContainer?: String, idleMinutes?: int, inheritFrom?: String, 
instanceCap?: int, label?: String, nodeSelector?: String, 
serviceAccount?: String, workingDir?: String, yaml?: 

Re: How to use containerTemplates in declarative kubernetes agent definition

2018-09-08 Thread Carlos Sanchez
https://github.com/jenkinsci/kubernetes-plugin/blob/master/README.md#declarative-pipeline

Note that it was previously possible to define containerTemplate but that
has been deprecated in favor of the yaml format.

containerTemplates also works but yaml syntax is preferred



On Sat, Sep 8, 2018 at 12:56 AM Matt Buckland 
wrote:

> Hello list,
>
> I'm running jenkins inside k8s:
> jenkins/jenkins:lts
> jenkins/jnlp-slave:3.23-1
> kubernetes-plugin: 1.12.4
>
> I'm using the following to define my agent:
>
>   agent {
> kubernetes {
>   label "${JOB_NAME}"
>   inheritFrom 'default'
>   containerTemplate {
> name 'jnlp'
> image '${ACCOUNT_ID}.dkr.ecr.${REGION}.
> amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}
> '
> resourceRequestCpu '200m'
> resourceLimitCpu '1'
> resourceRequestMemory '256Mi'
> resourceLimitMemory '1Gi'
>   }
>
>
>
> In the logs I have this message:
>
> Sep 07, 2018 5:11:34 PM
> org.csanchez.jenkins.plugins.kubernetes.pipeline.KubernetesDeclarativeAgent
> getAsArgs
> WARNING: containerTemplate option in declarative pipeline is deprecated,
> use containerTemplates
>
>
> I've not been able to find any documentation or examples showing how to
> use this containerTemplates option (note the "s" on the end). I've tried
> things such as:
>
>   containerTemplates [
> containerTemplate {
>   name 'jnlp'
>   image '${ACCOUNT_ID}.dkr.ecr.${REGION}.
> amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}
> '
>   resourceRequestCpu '200m'
>   resourceLimitCpu '1'
>   resourceRequestMemory '256Mi'
>   resourceLimitMemory '1Gi'
> }
>   ]
>
>
> and various other combinations, but I can't get it to work.
>
> Anyone have any suggestions?
>
> Many thanks,
>
> Matt
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/c98259fd-1aa4-40a1-890d-cb157cf3bf5b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CALHFn6MkJMQsSudHjs55zADR%2BQWhJT_HCqZM_RBGKaDrScUmfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to use containerTemplates in declarative kubernetes agent definition

2018-09-07 Thread Matt Buckland
Hello list,

I'm running jenkins inside k8s:
jenkins/jenkins:lts
jenkins/jnlp-slave:3.23-1
kubernetes-plugin: 1.12.4

I'm using the following to define my agent:

  agent {
kubernetes {
  label "${JOB_NAME}"
  inheritFrom 'default'
  containerTemplate {
name 'jnlp'
image 
'${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}'
resourceRequestCpu '200m'
resourceLimitCpu '1'
resourceRequestMemory '256Mi'
resourceLimitMemory '1Gi'
  }



In the logs I have this message:

Sep 07, 2018 5:11:34 PM 
org.csanchez.jenkins.plugins.kubernetes.pipeline.KubernetesDeclarativeAgent 
getAsArgs
WARNING: containerTemplate option in declarative pipeline is deprecated, 
use containerTemplates


I've not been able to find any documentation or examples showing how to use 
this containerTemplates option (note the "s" on the end). I've tried things 
such as:

  containerTemplates [
containerTemplate {
  name 'jnlp'
  image 
'${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}'
  resourceRequestCpu '200m'
  resourceLimitCpu '1'
  resourceRequestMemory '256Mi'
  resourceLimitMemory '1Gi'
}
  ]


and various other combinations, but I can't get it to work.

Anyone have any suggestions?

Many thanks,

Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c98259fd-1aa4-40a1-890d-cb157cf3bf5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.