Skip to content

Commit 53fd0e0

Browse files
committed
Added Power Query, jenkins cleanup old builds
1 parent d611d31 commit 53fd0e0

3 files changed

Lines changed: 86 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ Purpose: This repository documents my learning for Application Security: Checkm
3030

3131
# Miscellaneous
3232
* [Cloning machines on HyperV](hyperv/README.md)
33-
<!--* [CxIAST CI](cxiast-ci/README.md) -->
3433
* [Checkmarx services script](powershell/services/README.md)
3534
* [Create Active Directory Labs with Powershell](powershell/lab)
3635
* [Installing MS SQL 2017 on Ubuntu 18.04.3](linux/README-MSSQL.md)
3736
* [Common linux commands](linux/README.md)
37+
* [Jenkins Notes](jenkins/README.md)
38+
* [Power Query Example for CxSAST OData](powerQuery/README.md)
39+
<!--* [CxIAST CI](cxiast-ci/README.md) -->

jenkins/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Jenkins Notes
2+
* Author: Pedric Kng
3+
* Updated: 05 Dec 2019
4+
***
5+
6+
## Clean Up Old Builds
7+
8+
You can update the configuration of all existing jobs on a Jenkins Master by running the following Groovy Script within Manage Jenkins -> Script Console which will apply a permanent build discard policy to your jobs that you can configure by passing the desired values to the listed parameters.
9+
10+
```groovy
11+
// NOTES:
12+
// dryRun: to only list the jobs which would be changed
13+
// daysToKeep: If not -1, history is only kept up to this day.
14+
// numToKeep: If not -1, only this number of build logs are kept.
15+
// artifactDaysToKeep: If not -1 nor null, artifacts are only kept up to this day.
16+
// artifactNumToKeep: If not -1 nor null, only this number of builds have their artifacts kept.
17+
18+
import jenkins.model.Jenkins
19+
20+
def dryRun = true
21+
def daysToKeep = 30
22+
def numToKeep = 10
23+
def artifactDaysToKeep = -1
24+
def artifactNumToKeep = -1
25+
26+
27+
Jenkins.instanceOrNull.allItems(hudson.model.Job).each { job ->
28+
if (job.isBuildable() && job.supportsLogRotator() && job.getProperty(jenkins.model.BuildDiscarderProperty) == null) {
29+
println "Processing \"${job.fullDisplayName}\""
30+
if (!"true".equals(dryRun)) {
31+
// adding a property implicitly saves so no explicit one
32+
try {
33+
job.setBuildDiscarder(new hudson.tasks.LogRotator ( daysToKeep, numToKeep, artifactDaysToKeep, artifactNumToKeep))
34+
println "${job.fullName} is updated"
35+
} catch (Exception e) {
36+
// Some implementation like for example the hudson.matrix.MatrixConfiguration supports a LogRotator but not setting it
37+
println "[WARNING] Failed to update ${job.fullName} of type ${job.class} : ${e}"
38+
}
39+
}
40+
}
41+
}
42+
return;
43+
```
44+
45+
# References
46+
Best Strategy for Disk Space Management: Clean Up Old Builds [[1]]
47+
48+
[1]:https://support.cloudbees.com/hc/en-us/articles/215549798-Best-Strategy-for-Disk-Space-Management-Clean-Up-Old-Builds "Best Strategy for Disk Space Management: Clean Up Old Builds"

powerQuery/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Power Query Example for CxSAST OData
2+
* Author: Pedric Kng
3+
* Updated: 17 Dec 2019
4+
5+
CxSAST OData examples using Power Query
6+
* [List last scans of CxSAST projects ](#List-last-scans-of-CxSAST-projects)
7+
* [Check if result query is of OWASP TOP 10 category](#Check-if-result-query-is-of-OWASP-TOP-10-category)
8+
9+
***
10+
11+
## List last scans of CxSAST projects
12+
13+
```PowerQuery
14+
let
15+
Source = OData.Feed("http://192.168.137.45/Cxwebinterface/odata/v1/Projects?$expand=LastScan($expand=Results)"),
16+
#"Removed Other Columns" = Table.SelectColumns(Source,{"Id", "Name", "LastScanId"})
17+
in
18+
#"Removed Other Columns"
19+
```
20+
21+
## Check if result query is of OWASP TOP 10 category
22+
23+
```PowerQuery
24+
let
25+
Id=Number.ToText(1),
26+
ScanId=Number.ToText(1060719),
27+
ServiceUrl="http://192.168.137.45/Cxwebinterface/odata/v1/Results(Id=" & Id & ",ScanId=" & ScanId & ")/Query?$expand=QueryCategories($filter=TypeId eq 6)",
28+
ResultSource = OData.Feed(ServiceUrl, null,
29+
[
30+
Query=[],
31+
ODataVersion=4
32+
])
33+
in
34+
ResultSource
35+
```

0 commit comments

Comments
 (0)