Upload
intland-software
View
244
Download
3
Embed Size (px)
Citation preview
8/14/2019 Business Process Automation with codeBeamer & Groovy
1/53
GroovyGroovyBusiness ProcessBusiness Process
AutomationAutomationOlaf David
Colorado State University
Dept. of Civil Engineering, Dept. of Computer Science
8/14/2019 Business Process Automation with codeBeamer & Groovy
2/53
Olaf David, CSU/USDA 2
Automate and integrate software projectmanagement practices using CB with respectto Trackers
Forums Builds
Reports
Documents
Usersby using an efficient scripting approach.
ObjectiveObjective
8/14/2019 Business Process Automation with codeBeamer & Groovy
3/53
Olaf David, CSU/USDA 3
A First ExampleA First Exampleimport cbscript.CBimport static cbscript.CB.*
jf = CB.login("http://localhost:8080", bond", pass")proj = jf.projects.find{it.name == "MyProj"}
needsBuild = proj.trackers.find{it.name ==Bugs"}.items.any{
bug -> bug.status == "Fixed" && isThisMonth(bug.submitted)&& bug.priority > LOW && bug.hasCommits}
if (needsBuild) {println "starting build ....log = proj.builds.find{it.name == BuildApp"}.invoke()
println " Build done: ${log.status} println " Output: ${log.stdOut} "}
jf.logout();
8/14/2019 Business Process Automation with codeBeamer & Groovy
4/53
Olaf David, CSU/USDA 4
Principal ArchitecturePrincipal Architecture
cbscript
cb-api CB Server
DB SCM
Java API
-Low level, session centric and stateless-For a wide range of applications
Groovy API-High level, object centric, and productivity oriented-For process automation
Docs
8/14/2019 Business Process Automation with codeBeamer & Groovy
5/53
Olaf David, CSU/USDA 5
Semantic density and flexibility of scripts Usability/Efficiency aspects of scripts vs. plain Java
vs. Web UI
Remote Management of (multiple) CB server
Leveraging general scripting productivity(Groovy) Closures, Properties, Duck typing
Builder (DSL)
CB web UI does not allow complex queries No automation using the CB Web UI
Why Scripting?Why Scripting?
8/14/2019 Business Process Automation with codeBeamer & Groovy
6/53
Olaf David, CSU/USDA 6
Java 1.6+ Groovy 1.5+ cbscript-5.3.1.jar
Contains cb-api.jar of the same CB version
CB 5.3.x Network access to context
/cb/remote-api
Project user access (account)
PrerequisitesPrerequisites
8/14/2019 Business Process Automation with codeBeamer & Groovy
7/53Olaf David, CSU/USDA 7
API respects CB licenses, access permissions
Login/LogoutLogin/Logout
import cbscript.CBimport static cbscript.CB.*
jf = CB.login("http://localhost:8080", bond", "007")// orjf = CB.login(
url: "http://10.177.19.63:8080",login: "bond",password:pass")
// do some work.
jf.logout();
8/14/2019 Business Process Automation with codeBeamer & Groovy
8/53Olaf David, CSU/USDA 8
meta information can be obtained about thesession.
read/only
Session informationSession information
assert jf.login == "bond"assert jf.url == "http://localhost:8080"assert jf.user.realName == "Default System Administrator"
8/14/2019 Business Process Automation with codeBeamer & Groovy
9/53Olaf David, CSU/USDA 9
projects returns a list of projects Using closures to iterate, filter, search
Getting ProjectsGetting Projects
// list all projectsjf.projects.each {
println " id: ${it.id} name : ${it.name}"}
// find project(s)
assert jf.projects.find{it.name == "Moose"}.id == 2374assert jf.projects.find{it.id == 2374}.name == "Moosejf.projects.findAll{it.createdBy.name == "bond"}.each{
println it.name}
8/14/2019 Business Process Automation with codeBeamer & Groovy
10/53Olaf David, CSU/USDA 10
trackers returns a list of tracker Use closures to iterate, filter, search
Managing TrackerManaging Tracker
// get all tracker of the oms project.jf.projects.find{it.name == "oms"}.trackers.each{
tracker ->print tracker.nameprint tracker.description
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
11/53Olaf David, CSU/USDA 11
Closures help traversing resources
Obtain the Bug tracker in the oms project.Then find all the Closed items
Tracker Items queryTracker Items query
// Find items that are not Closeddef bugTracker = jf.projects.find{
it.name == "oms }.trackers.find {it.name == "Bugs"}
bugTracker.items.findAll{it.status != 'Closed'
}.each{println it.name
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
12/53Olaf David, CSU/USDA 12
Find all items assigned to me and submitted
last week
Tracker Items query (cont.)Tracker Items query (cont.)
bugTracker.items.findAll{it.assignedTo == jf.user && it.status == 'New'
}.each {println it.name
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
13/53Olaf David, CSU/USDA 13
Find a tracker item that has the string 'big' in
summary
Tracker Items query (cont.)Tracker Items query (cont.)
bugTracker.items.findAll{it.summary.contains('big problem')
}.each{println it.name
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
14/53Olaf David, CSU/USDA 14
All 'Resolved' items assigned to user 'bond'
that were submitted this month
Tracker Items query (cont.)Tracker Items query (cont.)
bugTracker.items.findAll{it.status == "Resolved" &&it.assignedTo.name == "bond" &&thisMonth(it.submittedAt)
}.each{
println it.name}
8/14/2019 Business Process Automation with codeBeamer & Groovy
15/53Olaf David, CSU/USDA 15
All tracker items submitted by me and do not
have an attached SCM commit.
Tracker Items query (cont.)Tracker Items query (cont.)
bugTracker.items.findAll{return it.submitter == jf.user && !it.hasCommits
}.each{println it.name
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
16/53Olaf David, CSU/USDA 16
All tracker items with high priority that are
still open and are not assigned yet to adeveloper.
Tracker Items query (cont.)Tracker Items query (cont.)
bugTracker.items.findAll{bug ->
bug.priority == HIGH && bug.status != Closed&& bug.assigned == null
}.each{
println it.name}
8/14/2019 Business Process Automation with codeBeamer & Groovy
17/53Olaf David, CSU/USDA 17
Use Task properties to configure
Priority: LOWEST, LOW, NORMAL, HIGH,HIGHEST
Submit a new taskSubmit a new task
// get the bug trackerdef bugs = jf.projects.find{
it.name == oms"}.trackers.find {it.name == "Bugs"}bugs.submit (
new Task(name:"My Bug",text:"This is a new Bug", priority:NORMAL)
)
8/14/2019 Business Process Automation with codeBeamer & Groovy
18/53
Olaf David, CSU/USDA 18
forums contains all project forums
Check for new posts today.
ForumsForums
def newsForum= jf.projects.find{it.name == "oms"}.forums.find {it.name == "News"}
newsForum.findAll{post -> isToday(post.submitted)
}.each{print it.text
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
19/53
Olaf David, CSU/USDA 19
forums contains all project forums
Check for new posts today.
Post a new Forum messagePost a new Forum message
news= jf.projects.find{it.name == "oms"}.forums.find {it.name =="News"}
news.post(new Message(subject:"New message",
text:"Content here ...")
8/14/2019 Business Process Automation with codeBeamer & Groovy
20/53
Olaf David, CSU/USDA 20
Check for all new posts from Joe Poster
submitted this week and print out themessage text.
Check for PostsCheck for Posts
news.findAll{post ->
post.submitter.realName == Joe Poster &&thisWeek(post.submitted)
}.each{
print it.text}
8/14/2019 Business Process Automation with codeBeamer & Groovy
21/53
Olaf David, CSU/USDA 21
Use artifact to reference a document or
folder in the project Documents Always absolute to Documents root.
DocumentsDocuments
prj = jf.projects.find{it.name == "cbtest"}doc = prj.artifact(download/EC2TW.txt)
assert doc.bytes.size() == 709assert doc.name == EC2TW.txt
assert doc.directory == false
8/14/2019 Business Process Automation with codeBeamer & Groovy
22/53
Olaf David, CSU/USDA 22
Copy a file from a CB server to the local FS
Documents (cont.)Documents (cont.)
prj = jf.projects.find{it.name == "cbtest"}doc = prj.artifact("download/EC2TW.txt")
new File('c:/tmp/test1').withOutputStream {it.write doc.bytes
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
23/53
Olaf David, CSU/USDA 23
builds contains all the builds of a project. Call invoke to execute the build on a CB
server. (Invoke is a synchronous call)
BuildsBuilds
build = prj.builds.find{it.name == "build-lib"}log = build.invoke();
8/14/2019 Business Process Automation with codeBeamer & Groovy
24/53
Olaf David, CSU/USDA 24
Build log captures the result of the build.
Builds (cont.)Builds (cont.)
build = prj.builds.find{it.name == "build-lib"}log = build.invoke();
assert log.output != nullassert log.error == nullassert log.status == Successful
assert log.successful == trueassert log.startedBy == jf.user
8/14/2019 Business Process Automation with codeBeamer & Groovy
25/53
Olaf David, CSU/USDA 25
Create associations by calling relate ontasks, artifacts, documents, etc.
Pass in the other task, artifact, documentand the kind of relationship (RELATED,CHILD, PARENT, DEPENDS)
AssociationsAssociations
bug = bugTracker.submit{new Task(name:"My Bug",
text:"This is a new Bug", priority:HIGH)}def lib = prj.artifact("builds/ngmf.jar")
bug.relate(lib, RELATED)
8/14/2019 Business Process Automation with codeBeamer & Groovy
26/53
Olaf David, CSU/USDA 26
Create a Association to many items in one
bulk operation (use closure) milestone is a tracker item
Associations (cont.)Associations (cont.)
readyToBuild = prj.trackers.find {it.name == "Bug
}.items.findAll {it.status == "Fixed" && thisMonth(it.submitted)
}
readyToBuild.each { bug -> milestone.relate(bug, DEPENDS) }
8/14/2019 Business Process Automation with codeBeamer & Groovy
27/53
Olaf David, CSU/USDA 27
Use CB.link() to create interwiki links fortask messages, forum posts, artifactdescriptions to reference other resources
InterWiki linksInterWiki links
build = prj.builds.find{it.name == "build-lib"}result = build.invoke();
String wikitext =!!Milestone info* Output Log Reference: ${CB.link(result)}
// resolves to:// Output Log Reference : [BUILDLOG:23456]
8/14/2019 Business Process Automation with codeBeamer & Groovy
28/53
Olaf David, CSU/USDA 28
Examples*Examples*
Examples*Examples*Examples*Examples*
Problem elevation
SCRUM support
SCM commit control
Auditable Build Management
* The examples demonstrate the support ofsome aspects of the topics above
8/14/2019 Business Process Automation with codeBeamer & Groovy
29/53
Olaf David, CSU/USDA 29
Increase the priority of all verified bugssubmitted before April that are assigned to
Joe that he did not fixed so far. Call this above every day (e.g. cron)
Simple Problem ElevationSimple Problem Elevationbugs.findAll{
bug ->bug.status == Verified" &&bug.assignedTo.name == Joe &&bug.spendHours == 0 &&!bug.hasCommits &&bug.submittedAt < new Date(2009,4,1)
}.each{it.priority++
}
8/14/2019 Business Process Automation with codeBeamer & Groovy
30/53
Olaf David, CSU/USDA 30
Prepare a Sprint review meeting
Check which tasks in 'Feature' requests in the 'oms'project were finished over the last 30 days.
SCRUM SupportSCRUM Support
jf.projects.find{it.name == "oms"}.trackers.find{it.name == "Features"}.items.findAll {task ->task.status == "Closed" && withinDays(task.modifiedAt, 30)
}.each {
println "${it.summary} - ${it.description}"}
8/14/2019 Business Process Automation with codeBeamer & Groovy
31/53
Olaf David, CSU/USDA 31
Prepare a Sprint review meeting
Get all the bugs that are still not closed and weresubmitted since April 1st 2008 (last sprint meeting)
SCRUM support (cont.)SCRUM support (cont.)
jf.projects.find{it.name == "oms"}.trackers.find {it.name =="Bugs"}.items.findAll{
it.status != "Closed" &&it.submittedAt > new Date(2008, 1, 4)
}.each {
println "${it.summary} - ${it.description}"}
8/14/2019 Business Process Automation with codeBeamer & Groovy
32/53
Olaf David, CSU/USDA 32
Creating a sprint backlog for allclosed tasks in the UI category ofnew features. The map contains the last seven days,
key: day diff to today (-1 is yesterday)
value: the number of closed tasks
SCRUM Support (cont.)SCRUM Support (cont.)def fitems = jf.projects.find{it.name=="oms"}.trackers.find{
it.name == "Features"}.items.findAll {it.category == UI
}(-7..0).each { day ->
map[day] = fitems.findAll {it.status == "Closed" && daydiff(it.modifiedAt, day)
}.size()}
println map// [-7:10, -6:3, -5:12, -4:4, -3:10, -2:5, -1:1, 0:2]
8/14/2019 Business Process Automation with codeBeamer & Groovy
33/53
Olaf David, CSU/USDA 33
Creating daily burndown chart data Call this script every day to track the hours
being burned in developing new features .
Create the graph based on this file.
SCRUM Support (cont.)SCRUM Support (cont.)hours = 0
def fitems = jf.projects.find{it.name=="oms"}.trackers.find{it.name == "Features
}.items.findAll {it.status == InDevelopment
}.each {hours += it.estimatedHours it.spentHours
}
f = new File(burndown.dat)today = new Date()f.append("${today} , ${hours}")
8/14/2019 Business Process Automation with codeBeamer & Groovy
34/53
Olaf David, CSU/USDA 34
A SVN commit message such as
svn commit m #1234 (status=Fixed) Changed loop orderwill trigger a status change on a task to fixed; no separate UIoperation needed. (Put this in cron and execute frequently)
SCM Commit triggers statusSCM Commit triggers statuschangechange
jf.projects.find{it.name == "OMSProject"}.trackers.find {
it.name == "Bugs}.items.findAll{it.hasCommits&& it.status != "Closed
}.each { task ->task.commits.each {if (it.message ==~ /.*\(status=(.*)\).*/ && today(it.commitedAt)) {
task.status = str.replaceAll(/.*\(status=(.*)\).*/, {
all, status -> return status })}
}}
8/14/2019 Business Process Automation with codeBeamer & Groovy
35/53
Olaf David, CSU/USDA 35
Requirement Flexible build process triggering by tracker content
information
Capture all information that relate to a build
Bugs BuildFeatures Build
Build process log Build
Build product Build
Developer independent build control
Flexible build notification Automated build product download
Auditable BuildAuditable BuildMana ementMana ement
8/14/2019 Business Process Automation with codeBeamer & Groovy
36/53
Olaf David, CSU/USDA 36
A
Bugs
FeatureRequests
DE
SCRepo
CommitUpdatePush
Pick upEditCommentStatus
Commit
Fixed
Implemente
Developer changes task status
The developers view
8/14/2019 Business Process Automation with codeBeamer & Groovy
37/53
Olaf David, CSU/USDA 37
Login and get the project reference
Auditable Build ManagementAuditable Build Management(1)(1)
import cbscript.*import static cbscript.CB.*
// login to CBjf = CB.login("http://localhost:8080", "bond", pass")
// find the project of interest
prj = jf.projects.find{it.name == "OMSProject"}
...
8/14/2019 Business Process Automation with codeBeamer & Groovy
38/53
Olaf David, CSU/USDA 38
A L
Bugs
FeatureRequests
Milestones
DE
SC
Build-lib
(2
Docume
MG
Identif
8/14/2019 Business Process Automation with codeBeamer & Groovy
39/53
Olaf David, CSU/USDA 39
Find candidates in Bugs and Featuresthat should lead to a new build
Combine the lists in to one.
Auditable Build ManagementAuditable Build Management(2)(2)...
// normal and higher priority bug fixed this month
readyBugs = prj.trackers.find {it.name == "Bug"}.items.findAll {it.status == "Fixed" && isThisMonth(it.submitted) &&
it.priority > LOW}
// A feature is implemented and there is a commitreadyFeatures = prj.trackers.find {it.name == Features"}.items.findAll {it.status == "Implemented" && it.hasCommits
}
// combine all features and bugs into one single listreadyList = readyBugs + readyFeatures...
8/14/2019 Business Process Automation with codeBeamer & Groovy
40/53
Olaf David, CSU/USDA 40
A L
Bugs
FeatureRequests
Milestones
DE
SC
Build-lib
Docume
3.1
(3
3.4
3.2
3.3
MG
Issue
8/14/2019 Business Process Automation with codeBeamer & Groovy
41/53
8/14/2019 Business Process Automation with codeBeamer & Groovy
42/53
Olaf David, CSU/USDA 42
A L
Bugs
FeatureRequests
Milestones
DE
SC
Build-lib
Docume
(4 MGNew milestone
8/14/2019 Business Process Automation with codeBeamer & Groovy
43/53
Olaf David, CSU/USDA 43
Create a WIKI description with the result info
(status and link to the Buildlog) Submit a new milestone task with the WIKI
content. Notification will be sent on submission.
Auditable Build ManagementAuditable Build Management(4)(4)...String wikiinfo = "!!Milestone info \n" +
"!Milestone Build:\n" +"* Build Status: ${result.status}\n" +"* Output Log Reference: ${CB.ref(result)}\n"
// create a new milestone in the milestone trackermt = prj.trackers.find {it.name == "Milestones"}milestone = mt.submit(
new Task(name:"MS-1.2", text:wikiinfo, priority:LOW))...
8/14/2019 Business Process Automation with codeBeamer & Groovy
44/53
Olaf David, CSU/USDA 44
A project L
Bugs
FeatureRequests
Milestones
DE
SC
Build-lib
Docume
(5
5.1 relate / link
5.2
MG
8/14/2019 Business Process Automation with codeBeamer & Groovy
45/53
Olaf David, CSU/USDA 45
Relate the new milestone to all bugs and
features in the readyList. Also relate it to the build product (ngmf.jar)
Auditable Build ManagementAuditable Build Management(5)(5)
...
// the build productdef lib = prj.artifact("builds/ngmf.jar")
// relate the milestone to all// bugs/features/and the build productmilestone.relate(lib, RELATED)readyList.each{ task -> milestone.relate(task, DEPENDS) }
...
8/14/2019 Business Process Automation with codeBeamer & Groovy
46/53
Olaf David, CSU/USDA 46
A project L
Bugs
FeatureRequests
Milestones
DE
SC
Build-lib
Docume
(6
6.2
MG
Fixed -> ReadyForTesting
Implemented ->
6.1 Task Status change
ngmf.jar
di bl ild
8/14/2019 Business Process Automation with codeBeamer & Groovy
47/53
Olaf David, CSU/USDA 47
Copy the build product to the local FS for testing
to skip manual download. Change the status for all bugs and features to
ReadyForTesting to indicate their processing
Auditable Build ManagementAuditable Build Management(6)(6)
...
// copy the new lib from CB to my local FS (optional)new File('c:/tmp/ngmf.jar').withOutputStream {
it.write lib.bytes}
// change the status in all items in readylistto// "ReadyforTesting"
readyList.each{ task -> task.status = "ReadyForTesting" }}
8/14/2019 Business Process Automation with codeBeamer & Groovy
48/53
Olaf David, CSU/USDA 48
Before invocation and Before invocation and
8/14/2019 Business Process Automation with codeBeamer & Groovy
49/53
Olaf David, CSU/USDA 49
After After
8/14/2019 Business Process Automation with codeBeamer & Groovy
50/53
Olaf David, CSU/USDA 50
.. and After .... and After ..
8/14/2019 Business Process Automation with codeBeamer & Groovy
51/53
Olaf David, CSU/USDA 51
.. and After .... and After ..
8/14/2019 Business Process Automation with codeBeamer & Groovy
52/53
Olaf David, CSU/USDA 52
.. and After .... and After ..
8/14/2019 Business Process Automation with codeBeamer & Groovy
53/53
http://cbscript.javaforge.com CB script examples, download cbscript.jar
https://codebeamer.com/cb/wiki/18830
Codebeamer API
http://groovy.codehaus.org All about Groovy
https://codebeamer.com Codebeamer
ReferencesReferences
http://cbscript.javaforge.com/https://codebeamer.com/cb/wiki/18830http://groovy.codehaus.org/https://codebeamer.com/https://codebeamer.com/http://groovy.codehaus.org/https://codebeamer.com/cb/wiki/18830http://cbscript.javaforge.com/