Skip to content

Instantly share code, notes, and snippets.

View alipandidan's full-sized avatar

Ali Pandidan alipandidan

View GitHub Profile
@alipandidan
alipandidan / list_jenkins_credentials.groovy
Created July 11, 2019 07:23
List Jenkins Credentials
def StandardUsernameCredentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, Jenkins.instance, null, null);
for (c in StandardUsernameCredentials) {
println(c.id + ": " + c.description)
}
def StandardUsernamePasswordCredentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class, Jenkins.instance, null, null);
for (c in StandardUsernamePasswordCredentials) {
println(c.id + ": " + c.description)
}
@alipandidan
alipandidan / entrypoint.sh
Created August 10, 2019 15:56
Suitable entrypoint for docker
#!/bin/sh
set -e
if [ $(echo "$1" | cut -c1) = "-" ]; then
echo "$0: assuming arguments"
set -- myapp "$@"
fi
if [ $(echo "$1" | cut -c1) = "-" ] || [ "$1" = "myapp" ]; then
@alipandidan
alipandidan / sendKey.ps1
Created August 12, 2019 14:44
Send keystrokes to apps
# Dismiss all Microsoft Visual Studio Community 2015 propmpts during installation automatically
while (Get-Process | Where-Object {$_.Description -eq "Microsoft Visual Studio Community 2015 with Updates"})
{
Start-Sleep -Seconds 60;
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Visual Studio');
$wshell.SendKeys("{ENTER}")
}
@alipandidan
alipandidan / postman_pre_request_script.js
Created December 5, 2019 11:20
Get bearer token automatically from API and use it in (Postman as Pre-request scipts)
# Might be useful in Spring boot apps
const postRequest = {
url: 'http://<URL>/auth/login',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'application/json',
raw: JSON.stringify(
{
@alipandidan
alipandidan / auto_tags.py
Created December 6, 2019 08:58 — forked from rkrzr/auto_tags.py
Automatically generate ansible tags of the same name for each role in a playbook
"""
This module implements an Ansible plugin that is triggered at the start of a playbook.
The plugin dynamically generates a tag for each role. Each tag has the same name as its role.
The advantage of this is that it saves you some boilerplate, because you don't have to wrap
all tasks of a role in an additional block and assign a tag to that.
Additionally, it works automatically when you add new roles to your playbook.
Usage is exactly the same as without this plugin:
@alipandidan
alipandidan / abort_previous_build.groovy
Last active May 5, 2020 16:29
Abort previous Jenkins build
import hudson.model.Result
import hudson.model.Run
import jenkins.model.CauseOfInterruption.UserInterruption
def call() {
// https://stackoverflow.com/a/49901413/4763512
Run previousBuild = currentBuild.rawBuild.getPreviousBuildInProgress()
while (previousBuild != null) {
if (previousBuild.isInProgress()) {
def executor = previousBuild.getExecutor()
@alipandidan
alipandidan / ci_jobs.groovy
Created May 16, 2020 20:47 — forked from tknerr/ci_jobs.groovy
Example JobDSL for a multibranchPipelineJob which keeps only the last 10 builds
// define the bitbucket project + repos we want to build
def bitbucket_project = 'myproj'
def bitbucket_repos = ['myrepo1', 'myrepo2']
// create a pipeline job for each of the repos and for each feature branch.
for (bitbucket_repo in bitbucket_repos)
{
multibranchPipelineJob("${bitbucket_repo}-ci") {
// configure the branch / PR sources
branchSources {
@alipandidan
alipandidan / keepawake.ps1
Created May 23, 2020 14:24 — forked from jamesfreeman959/keepawake.ps1
A very simple PowerShell script to keep a Windows PC awake and make lync think the user is active on the keyboard
# Useful references:
#
# https://superuser.com/questions/992511/emulate-a-keyboard-button-via-the-command-line
# https://ss64.com/vb/sendkeys.html
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell?forum=winserverpowershell
# https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/
#
# Future enhancements - use events rather than an infinite loop
while (1) {
$wsh = New-Object -ComObject WScript.Shell
@alipandidan
alipandidan / git_hook_telegram_notification.sh
Created October 8, 2020 23:02
Telegram notification git hook
COMMITS=$(git --no-pager log origin/master..HEAD --format="- [%h] %B")
API_URL="https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}"
curl --silent -o /dev/null \
--header "Content-Type: application/json" \
--request POST \
--data "{\"text\": \"${COMMITS}\"}" \
$API_URL
@alipandidan
alipandidan / update_commit_author.sh
Created October 13, 2020 12:12
Update git commit author info
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="<OLD_EMAIL>"
CORRECT_NAME="<NEW_NAME>"
CORRECT_EMAIL="<NEW_EMAIL>"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"