Skip to content

Instantly share code, notes, and snippets.

View or-shachar's full-sized avatar

Or Shachar or-shachar

View GitHub Profile
@or-shachar
or-shachar / wix_2nd_party.bzl
Created February 10, 2021 15:14
Example for external repositories bazel definition
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
def wix_deps():
git_repository(
name = "wix_a",
remote = "git://github.com:wix-example/wix-a.git",
commit = "[latest_wix_a_commit]",
)
@or-shachar
or-shachar / bazel-vmr-wrapper.sh
Last active February 15, 2021 08:23
Pseudocode for bazel wrapper that generates external repositories file
current_branch <- get_current_branch()
if (force_latest): # for specific CI cases
recreate_file(current_branch)
else:
git_aware_file_for_branch <- find_locked_file_for_branch(current_branch)
git_ignored_file <- find_git_ignored_file_for_branch(current_branch)
if (git_aware_file_for_branch):
symlink(current_2nd_party_file, git_aware_file)
else if (git_ignored_file):
@or-shachar
or-shachar / find_trigger_user_id.groovy
Last active July 30, 2019 12:26
How to recursively find the userId that triggered the build in Jenkins
import net.sf.json.JSONException
node {
// Just example of how to use the function
currentBuild.description = find_trigger_user(currentBuild)
}
def find_trigger_user(build){
cause = build.buildCauses.getJSONObject(0)
try{
return cause.getString("userId")
{
"id": string,
"projectId": string,
"status": enum(Status),
"statusDetail": string,
"steps": [
{
// some steps that invoke bazel
}
],
@or-shachar
or-shachar / GithubWebhookHandler.scala
Last active July 17, 2018 22:20
Github webhook handler digest handler
import org.apache.commons.codec.digest.{HmacAlgorithms, HmacUtils}
class WebHookHandler(webhookSecret:String) {
private val hmacDigest = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, webhookSecret)
private val xHubSignaturePattern = "sha1=(.+)".r
private def validate(xHubSignature: String, body: String): Boolean = {
xHubSignature match {
case xHubSignaturePattern(sha1) => sha1 == hmacDigest.hmacHex(body)
import java.io.FileInputStream
import java.security.interfaces.RSAPrivateKey
import java.util.Date
import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
class GCBTokenProvider(privateKey: RSAPrivateKey, privateKeyId: String, serviceName: String, api: String, user: String) {
def getToken: String = {
@or-shachar
or-shachar / ResultStoreAPISample.java
Last active August 6, 2018 08:24
working example
// Using com.auth0:java-jwt:3.4.0
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
// Using com.google.api-client:google-api-client:1.23.0
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
// Using commons-io:commons-io:2.6
import org.apache.commons.io.IOUtils;
import com.cloudbees.hudson.plugins.folder.Folder
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution
dryRun = true
def printIfBuildIsRunning(job){
def item = job.getLastBuild()
if(item!=null && item.isBuilding()) {
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution
projectFullName = 'folder/job-name'
dryRun = false
if(!(projectFullName in String)) {
throw new Exception('PARAMETER ERROR: projectFullName must be a string.')
}
/*
Jenkins - If found "lookup_string" in last run of a job - triggers it again with the same parameters
*/
job_name="some-job" //I have multiple jobs with the same simple name under multiple folders
lookup_string="something inside the log" // the line we want to look for
instance = Jenkins.instance
def jobs = instance.allItems.findAll{it.name==job_name}
count = 0
for (job in jobs){
lastRun = job.lastCompletedBuild