Skip to content

Instantly share code, notes, and snippets.

View hayderimran7's full-sized avatar

Imran Hayder hayderimran7

View GitHub Profile
@hayderimran7
hayderimran7 / gist:9246dd195f785cf4783d
Created February 13, 2015 22:38
How to solve "sudo: no tty present and no askpass program specified" when trying to run a shell from Jenkins
Running shell scripts that have contain sudo commands in them from jenkins might not run as expected. To fix this, follow along
Simple steps:
1. On ubuntu based systems, run " $ sudo visudo "
2. this will open /etc/sudoers file.
3. If your jenkins user is already in that file, then modify to look like this:
jenkins ALL=(ALL) NOPASSWD: ALL
4. save the file by doing Ctrl+O (dont save in tmp file. save in /etc/sudoers, confirm overwrite)
5. Exit by doing Ctrl+X
6. Relaunch your jenkins job
@hayderimran7
hayderimran7 / gist:d791c09997dc28eda3fb
Created February 13, 2015 22:41
How to get names of all jenkins plugins installed in your master
easiest way is by going through jenkins UI, but if you want to know from CLI, follow along:
1. cd to jenkins home directory i.e. 'cd /var/lib/jenkins'
2. cd to plugins folder
3. run command : ls -ld */ | awk '{print $9}'
e.g.
~/plugins$ ls -ld */ | awk '{print $9}'
4. this will show a list of plugins installed
@hayderimran7
hayderimran7 / gist:78421229af85ae90177b
Last active February 15, 2021 17:22
So what is the 'credentials-id' parameter and how to use it correctly in jenkins-job-builder yaml file of your job?
It took me a while, after multiple knocks on all openstack/cloudbees/jenkins IRCs and googling around, all of them proved to be fruitless that I finally figure what the deal about this parameter all about?
before posting the exact details, i just have a little rant : WHY IS THIS NOT IN THE DOCS OF JENKINS JOB BUILDER (JJB ) ???
Jenkins job builder docs are pretty concise and dont go into much details,
but anyway:
=================================
what is credentials-id parameter?
=================================
so you are writing a yaml file for your job 'foo.yaml' and you need to use a git repo, lets say its in github,
now github private repos are snowflaky where you need to provide credentials to github in order to clone them. Following is step-by-step howto:
@hayderimran7
hayderimran7 / gist:179e0ca33d7c93429ba7
Created February 17, 2015 02:57
Sphinx builder how to fix 'WARNING: Definition list ends without a blank line; unexpected unindent.'
recently i came up with this warning which was failing my job .
The reason this warning happens is that for a multi-line comment/description, you should give '\' after each line except the last line.
so lets i have a doc comment like this:
'this is a test
comment which describes
something about this module.'
Above docstring will obviously in sphinx build job, so correct way is :
'this is a test \
comment which describes \
@hayderimran7
hayderimran7 / gist:455edb0fc2de001f7820
Last active August 29, 2015 14:16
Fix docker devicemapper deletion.
So i was trying to completely uninstall docker , i did package uninstall successfully.
but removing a package doesnt remove the docker data that lives in `/var/lib/docker`.
well i did `rm -rf /var/lib/docker/*` i deleted all folders containing metadata and stuff ,
but there was one folder that was pain in neck .. and that was /var/lib/docker/devicemapper.
all it said `could not delete devicemapper: device or map busy` .
first of all, i should not be using devicemapper at all because docker uses aufs and it works pretty fine.
but since its hard to patch for kernel(well not hard, quite cumbersome) the aufs3 package,
so anyway if you are using devicemapper for docker, and trying to completely uninstall it , here is the howto:
## STEPS TO REMOVE DEVICEMAPPER FOLDER ###
* first try ` rm -rf /var/lib/docker`
@hayderimran7
hayderimran7 / groovy-create-user.md
Last active April 10, 2024 17:29
Jenkins Groovy enable security and create a user in groovy script

This is a snippet that will create a new user in jenkins and if security has been disabled , it will enable it :)

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount("MyUSERNAME","MyPASSWORD")
instance.setSecurityRealm(hudsonRealm)
@hayderimran7
hayderimran7 / Jenkins_ssh_groovy.md
Last active October 5, 2020 04:47
Groovy script to add credentials from SSH master key located at ~/.ssh/

Perhaps the simplest way of adding the global ssh creddentials is to just select "from a file on master ~/.ssh" and jenkins will automatically scan for is_rsa files in that folder..

but we like to do stuff from scripts.. UI is for lazy folks :):D so in groovy, i was wondering how would i approach it.. well i have to admit there was UI involved in initial help. I went to manage credentials > global credentials> add ssh username private key Option Now i had no idea how to approach to this page using groovy. ofcourse there is a plugin for ssh creds.. that i need to work with :) so here i made use of UI 's help :

  • I selected the text "Username" , or you can select "password" ..doesnt matter , we need to know where there params are coming from
@hayderimran7
hayderimran7 / get-api-token-of-user-jenkins-groovy.md
Last active June 7, 2021 14:24
jenkins groovy get API token of a user

This is pretty simple snippet to get API Token of a user , lets say "MYUser" in jenkins.
its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins, and you need to get the api token which JJB needs inorder to update jobs to ..
run this code in either jenkins script console , or as i prefer, in form of init.groovy.
so when jenkins master starts, i create a user for JJb.
after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

///////////////////////////////////////////////////////////////////////
@hayderimran7
hayderimran7 / no-sudo-for-docker-on-opensuse
Created April 21, 2015 05:44
Run docker without sudo on opensuse
If you have ever used opensuse , you will how much opensuse cares about the holiness of sudo.. want to print a paper? sure but you need sudo access. want to connect to wifi , oh you about you do it with sudo.?
if dont believe me its true, might have a look at a classic rant by father of Linux , Linus Torvalds who literally goes NSFW on opensuse and its shitty policy mechanism on `sudo`. Check here what Linus said : https://plus.google.com/+LinusTorvalds/posts/1vyfmNCYpi5
anyways, if you wana run docker without sudo, normal recommended way as by docker docs, is to do following:
$ sudo usermod -aG docker <username>
where <username> is the user currently logged in to system.
so for the mighty highness of opensuse, where everything seems to have shitty grip of reality , here is complete step by step procedure to run docker without sudo :
@hayderimran7
hayderimran7 / suseeeeee
Created May 19, 2015 21:16
Install vagrant + virtualbox on opensuse
Heaven forbid if u are using "basic" OS like OpenSuse , as i have been sturggling with it.. :(
i feel like a lot gists will go on my experiences with this terrible OS ..thanks openSuSE ..
ok here is how u install vagrant and virtualbox on SUSE based OS in the right way ..
======================
1.install virtualbox4.3