How Do You Get a Jenkins Plugin to Work That Normally Uses the Internet When You Have No Internet Access?

Problem scenario
Your Jenkins server has no access to the internet.  You are trying to run a  Jenkins job that involves a plugin.  You receive a 407 error when a job runs.  You look at the console output and see java.io error that deals with being unable to connect to a website.  How do you customize a Jenkins plugin to retrieve installation media from an internal server instead of a default website URL?

Solution
Go to Manage Jenkins -> Global Tool Configuration.  Find the plugin.  Modify the plugin configuration there.

Why Cannot You Use a Python Module in a Program or the Command Prompt When One Will Work but Not the Other?

Problem scenario
You have a Python program use an import statement, but the program fails.  From the Python command prompt, you can import the module.  Why is it different?

Possible Solution #1
You may be using Python version 3 for either the command prompt or the program and Python version 2 for the complement (either the command prompt or the program). Try these commands:

python --version
python3 --version

Possible Solution #2
See where the potential imports are. Enter the Python command prompt once with python (or python2) and a second time with python3 (or python). Then run these two commands from that line (where >>> is just a reference a not part of the command itself):

>>> import sys
>>> print(sys.path())

Possible Solution #3
In the Python program, temporarily add these two lines, purely as a diagnostic, before the import line that is causing the problem, and run your program:

import sys
print(sys.path)

How Do You Get the Sonar Scanner Tool to Be Reinstalled on a Jenkins Slave?

Problem scenario
You want to uninstall the Sonar Scanner CLI to force its reinstallation as you have a Jenkins job that does the installation automatically.  What do you do to uninstall it and make the Jenkins job do the installation again?

Solution
1.  For the Sonar Scanner job that will run, configure it so it runs on a specific slave.  Log into Jenkins.  Go to the Jenkins job, go to Configure, and search for the word "Restrict".  Check the box near this word.  For the "Label" field, type in the hostname of the Linux server that has Sonar Scanner.

2.  Go to "Manage Jenkins".  Go to "Global Tool Configuration".   Go to SonarQube Scanner Installations.  Look at the "Name" field.  Remember the value.

3.  Log into the back end of the Jenkins slave that has Sonar Scanner installed.  Run this command but replace "foobar" with the value found in step #2:  sudo find / -name foobar | grep SonarRunnerInstallation

4.  Move the directory (e.g., /home/jenkins/jenkins_slave/tools/hudson.plugins.sonar.SonarRunnerInstallation/contint) that was found above to your user's home directory or somewhere in a completely different path (e.g., /tmp/).

5.  Re-run the Jenkins job.  The installation should be triggered from the absence of the directory on the slave server as Jenkins has a "remote directory" to look for.

How Do You Get a GCP Server to Present a Website on the Internet?

Problem scenario
You want to browse the web UI of a web application that you set up on a Linux machine in GCP.  How do you get a web service (e.g., Nginx, Apache web server, SonarQube or Jenkins) to work when the server is in Google Cloud Platform?

Solution
Prerequisites
This assumes you have deployed the web application.  If you want to deploy Nginx, see this link.  If you want to deploy Apache web server, see this link.  If you want to install SonarQube, see this link.  If you want to deploy Jenkins, see this link.

Procedures
Overview:  Create a firewall rule from the source IP address of your web browser. 

1.  After you are logged into GCP go to VPC Network -> Firewall Rules. 
2.  Click on "Create firewall rule".
3.  To find the source IP address go to the workstation where you will browse from and go to ipchicken.com. 
4.  The port may vary (e.g., for SonarQube you may need 9000 or for Jenkins you may need 8080).  If you want the application to work from any workstation, use the source IP address range of "0.0.0.0/0" with no quotes.  
5.  For a Tag, enter an alphanumeric string.  Remember the tag you give this rule.
6.  Next go to "Compute Engine" -> "VM Instances" page. 
7.  Click on the hyperlink for the VM that has the web service. 
8.  Click on "Edit" to modify the details. 
9.  In the "Network Tags" field, enter the unique tag you entered above (the alphanumeric string).  
10.  Go to the Firewalls section.  Click the boxes for "Allow HTTP traffic" and "Allow HTTPS traffic".
11.  Click "Save".  The changes will take effect after a few minutes.

How Do You Troubleshoot the Error “Invalid Option” When Trying to Delete a File That Has a File Name with the First Character Being a Hyphen or Dash “-“?

Problem scenario
You have some files that have a name that starts with a hyphen (e.g., from some Bash script that did not work as intended):

-the
-filename
-q

You cannot delete them using rm.  You get an error about an "invalid option".  What should you do to delete this files that should never have been created in the first place?

Solution
Use the rm flag "--" such as this:

rm -- -the
rm -- -filename
rm -- -q

How Do You Find Your Phone Number with an Android Phone?

Problem scenario
You are using an Android phone, and you want to find its phone number.

Solution
1.  Turn on your Android phone.
2.  Go to Tools -> Settings
3.  Scroll down to the "System" section and click on About phone ->  SIM status.  You should see the phone number at the bottom.

If you want to buy a new Android phone, you can click here.

How Do You Test the Database Credentials (username and password) of a PostgreSQL Database Using Bash?

Problem scenario
You are not sure if the username and password to a PostgreSQL database work.  What do you do?

Solution
Run this one-line command:

psql -d "postgresql://jdoe:coolpassword@localhost/foobardb" -c "select now()"

# Replace "jdoe" with the SQL database username
# Replace "coolpassword" with the user's password
# Replace "foobardb" with the name of the database you are authenticating too
# If you have the PostgreSQL client installed (so psql works) and the database is remote, use the FQDN instead of the "localhost"

This solution was based on this posting.

How Do You Configure Jenkins Builds to Avoid Slave Servers That Are Either Windows or Linux?

Problem scenario
You are configuring Jenkins jobs.  You want certain jobs to only run on Windows slaves (e.g., PowerShell jobs) and certain jobs to only run on Linux slaves (e.g., Bash scripts).  You want to force a job force a selection of a slave server to avoid Windows or Linux servers.  How do you have Jenkins avoid slave servers based on the OS architecture?

Solution
1.  Go to the job and click on "Configure" or create a new job.

2.  Search for the word "Restrict".  

3.  Click the checkbox for Restrict.  Enter "windows" with no quotes if you want the job to only run on a Jenkins slave server running Windows.  Enter "linux" with no quotes if you want the job to only run on a Jenkins slave server running Linux.  

Optional step
There are more sophisticated restrictions you can place on the Jenkins build.  Click on the blue question mark icon on the right.  This will explain the syntax for how to force the Jenkins jobs to run on Linux or Windows exclusively.  One common usage is to use as a label the hostname of the slave server.  This will restrict the builds to this slave server exclusive of other servers.

How Do You Find the Version of SonarQube That You Have Installed?

Problem scenario
You have installed SonarQube.  You want to know what version you are using.  How do you find out?

Solution
Go to the web UI for SonarQube.  It may be as simple as opening a web browser and entering the external IP address of the server.  Without logging in scroll to the bottom.  You should see something like this near the bottom:  Version 6.7 (build 33306)

How Do You Change the Base URL for SonarQube?

Problem scenario
Currently you have to enter a URL like this to access SonarQube's web UI:

http://servername.com:9000/sonar

You want to be able to type no path (e.g., no "sonar") in the web browser.  You want to just enter the hostname in the web browser and the port number of the SonarQube server.  What should you do?

Solution
Go to the conf directory [that is a sibling] with the sonar.properties file.  Find the "context" stanza.  It will have a string "sonar.web.context".  Comment it out.  By default it will be "/".

To learn more, see this posting.