Presentation is loading. Please wait.

Presentation is loading. Please wait.

DevSecOps: The Java Developer’s Guide to Automating with Groovy

Similar presentations


Presentation on theme: "DevSecOps: The Java Developer’s Guide to Automating with Groovy"— Presentation transcript:

1 DevSecOps: The Java Developer’s Guide to Automating with Groovy
Jeanne Boyarsky Tuesday Oct 23, 2018 Oracle Code One – DEV4959 speakerdeck.com/boyarsky

2 Use Groovy?

3 About Me 16 years as Java Developer Years of tooling & Groovy

4 Wednesday Recommendations
Date Time Title Speaker Wed Oct 24 1:30-2:15 Functional Programming in Java, Groovy & Kotlin Ken Kousen 2:30-3:15 JVM Languages: Compare (Java, Kotlin, Groovy, Scala) Leonardo Lima, Nikhil Nanivadekar & Donald Raab Which Java Version from Which Java Vendor with What Support Jeanne Boyarsky

5 Will cover Groovy syntax & idioms Using Groovy from Nexus
Using Groovy from Jenkins Live demo

6 This morning’s lab HOL-Automating-Stack-Groovy Nexus - Groovy Jenkins - Groovy Bonus – Java Sonar rule

7 Groovy Syntax & Idioms

8 Groovy Java

9 Java  Groovy int lastYear = 2017; int year = 2018 def nextYear = 2019
Can use Java syntax Without semicolon or type

10 Strings def city = 'SF' println 'Here: $city' println "Here: $city" println "In ${city.class}" Java String GString Here: $city Here: SF In class java.lang.String

11 Multiline string ______
def name = 'Jeanne' def text = """ Name ______ $name """ println text Name ______ Jeanne

12 What does this print? ______
def name = 'Jeanne' def text = ’’’ Name ______ $name ’’’ println text Name ______ $name

13 Getters vs properties def animal = 'dog' println animal.getBytes() println animal.bytes

14 == vs equals() Can use Java syntax True!
def monday ='monday' def nextMonday = new String('monday') def tuesday ='tuesday' println monday == null println null == monday println monday == tuesday println monday == nextMonday Can use Java syntax True!

15 What is the truth? Value Result Null False Empty String Empty List
1 character String True

16 Elvis has entered the building
println Jenkins.instance .getItemByFullName(jobName) ?.lastBuild ?.timestamp ?.time Image from

17 Optional Parens def ch = 'abc'.charAt 1 println ch
Optional when no ambiguity Ambiguity: Zero params Within println

18 ArrayList++ ArrayList does what now?!
def list = ['cookie', 'chocolate’] list << 'candy' println list.getClass() class java.util.ArrayList println list[1] chocolate ArrayList does what now?!

19 ArrayList++ println list [cookie, chocolate, candy] println list[-1]
println list.min() list.sort() [candy, chocolate, cookie]

20 MetaClass def list = [1,3,5,7] println list.metaClass.methods println list.metaClass.methods*.name.sort().unique() Method signatures Method names

21 Streams/lambas def list = [1,3,5,7] list.stream().filter({n -> n >= 5}).forEach({n -> System.out.println(n)}) println list.grep { num -> num >= 5 } println list.grep { it >= 5 } grep vs filter less plumbing “it” implies param

22 Countdown! (10..1).each{ println "--> $it" } println 'Blast off!'

23 Stream Mapping Java Groovy filter grep map collect forEach for limit
take distinct unique anyMatch/allMatch any/every findFirst find

24 Lazy? Groovy; not lazy Java streams

25 Functions incrementBy = 4; def add(num) { num + incrementBy } println add(2) no def Types optional Return optional

26 Named Params def config = new SelectorConfiguration( name: ‘selector', description: ‘packages', ) Only the default constructor exists!

27 More on Groovy lang.org/next/html/documentation/working-with- collections.htm jdk/overview-summary.html

28 Using Groovy in Jenkins

29 println 'Hello Oracle Code One! '
println GroovySystem.version Hello Oracle Code One! 2.4.11

30

31 Jenkins/Hudson split

32 System scripts can access object model
Can’t choose Groovy version

33 Three ways to find methods
JavaDoc Groovy def instance = Jenkins.getInstance() println instance.metaClass.methods*.name .sort().unique() println instance.metaClass.methods Google Reuse existing scripts

34 Sample Object model code
import jenkins.model.Jenkins def instance = Jenkins.getInstance() def realm = Jenkins.getInstance().securityRealm realm.createAccount('olivia', 'olivia') instance.save()

35 Pipeline Syntax Helper

36 Convert to Pipeline Plugin

37

38

39 Script Security Plugin
ERROR: Build step failed with exception org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance Options: Approve each script manually Sandbox - whitelist APIs Authorized Build plugin to run as admin

40 Using Groovy in Nexus

41 log.info'Hello Oracle Code One! ’
log.info GroovySystem.version

42 Nexus Built Ins ScriptApi core (CoreApi) blobStore (BlobStoreApi)
repository (RepositoryApi) security (SecurityApi)

43 And then there is container GlobalComponentLookupHelper
selectorManager = container.lookup(SelectorManager.class.name) securitySystem = container.lookup(SecuritySystem.class.name) authorizationManager = securitySystem.getAuthorizationManager('default')

44 Eclipse (or IntelliJ)

45 Live demo

46 What we will cover Code Examples Walkthrough Nexus object model
Jenkins object model Jenkins pipeline Demo – Nexus and Jenkins

47 ???


Download ppt "DevSecOps: The Java Developer’s Guide to Automating with Groovy"

Similar presentations


Ads by Google