Bitnami Jenkins For Huawei Cloud

Description

Jenkins is the leading open source Continuous Integration and Continuous Delivery (CI/CD) server that enables the automation of building, testing, and shipping software projects.

First Steps With The Bitnami Jenkins Stack

Welcome to your new Bitnami application running on Huawei Cloud! Here are a few questions (and answers!) you might need when first starting with your application.

What Credentials Do I Need?

You need two sets of credentials:

  • The application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.
  • The server credentials, consisting of an SSH username and key. These credentials allow you to log in to your Huawei Cloud server using an SSH client and execute commands on the server using the command line.

What Is The Administrator Username Set For Me To Log In To The Application For The First Time?

Username: user

What Is The Administrator Password?

To obtain the administrator password, click the "Remote Login" menu option next to the server name in the Huawei Cloud Server Console. This will launch a new browser window with an encrypted login session. The application password will be displayed on the login welcome screen.

What SSH Username Should I Use For Secure Shell Access To My Application?

SSH username: root

How Do I Get My SSH Key Or Password?

You would have created or imported an SSH key pair at the time of deploying the server. Use the same key pair for secure shell access to the server.Click here for more information.

What Are The Default Ports?

A port is an endpoint of communication in an operating system that identifies a specific process or a type of service. Bitnami stacks include several services or servers that require a port.

Remember that if you need to open some ports you can follow the instructions given in theFAQto learn how to open the server ports for remote access.

Port 22 is the default port for SSH connections.

Bitnami opens some ports for the main servers. These are the ports opened by default: 80, 443.

How To Start Or Stop The Services?

Each Bitnami stack includes a control script that lets you easily stop, start and restart services. The script is located at/opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, such as Apache only, by passing the service name as argument:

sudo /opt/bitnami/ctlscript.sh restart apache

Use this script to stop all services:

sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

sudo /opt/bitnami/ctlscript.sh

How To Install Plugins For Jenkins?

To install and use a Jenkins plugin, you must manually create the plugin directories under the/opt/bitnamidirectory and change the directory ownership to thetomcatuser. For example, to use the Gradle plugin with Jenkins, follow these steps:

cd /opt/bitnami

sudomkdir .gradle

sudochown -R tomcat:tomcat .gradle

How To Create A Full Backup Of Jenkins?

Backup

The Bitnami Jenkins Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

  • Change to the directory in which you wish to save your backup:
  • cd /your/directory
  • Stop all servers:
  • sudo /opt/bitnami/ctlscript.sh stop
  • Create a compressed file with the stack contents:
  • sudo tar -pczvf application-backup.tar.gz /opt/bitnami
  • Restart all servers:
  • sudo /opt/bitnami/ctlscript.sh start

You should now download or transfer theapplication-backup.tar.gzfile to a safe location.

Restore

Follow these steps:

  • Change to the directory containing your backup:
  • cd /your/directory
  • Stop all servers:
  • sudo /opt/bitnami/ctlscript.sh stop
  • Move the current stack to a different location:
  • sudo mv /opt/bitnami /tmp/bitnami-backup
  • Uncompress the backup file to the original directoryv
  • sudo tar -pxzvf application-backup.tar.gz -C /
  • Start all servers:
  • sudo /opt/bitnami/ctlscript.sh start

If you want to create only a database backup, refer to these instructions forMySQLandPostgreSQL.

How To Upgrade Jenkins?

To upgrade Jenkins without losing your data, download the latestjenkins.warfile, copy it to yourapache-tomcat/webappsdirectory and restart Tomcat.

It is recommended to create a backup of the previousjenkins.warfile. You may want to revert to the previous version if you find any issues after upgrading.

Upgrading Only Jenkins

Execute the following steps to upgrade only Jenkins:

  • Stop the server:
  • sudo /opt/bitnami/ctlscript.sh stop tomcat
  • Copy your previous .war file in case you need to restore it:
  • cd /opt/bitnami
  • cp apache-tomcat/webapps/jenkins.war apps/jenkins/jenkins.war.bak
  • Remove all Jenkins files to force Tomcat to deploy the new version:
  • rm -r apache-tomcat/webapps/jenkins
  • rm -r apache-tomcat/webapps/jenkins.war
  • rm -r apache-tomcat/work/Catalina/localhost/jenkins
  • Download the new version of Jenkins:
  • wget
  • mv jenkins.war apache-tomcat/webapps/
  • Start the server:
  • sudo /opt/bitnami/ctlscript.sh start tomcat

Upgrading All The Components

Start a new image with the latest Jenkins version and move the content of/opt/bitnami/apps/jenkins/jenkins_homein your current installation to the new installation. Then, restart the server.

Upgrading Jenkins Plugins

To upgrade the Jenkins plugins to the latest version, please follow these instructions:

  • Enter the server's IP in your browser, then log in to the Jenkins dashboard using your credentials.
  • Click on "Manage Jenkins" in order to access the admin panel:
  • Click on "Manage Plugins":

  • On the resulting page, click on "Download now and install after restart":

Jenkins will now download the latest version of your plugins and will install them automatically.

How To Enable SSL Access Over HTTPS?

You can configure Apache Tomcat to enable SSL access to applications using HTTPS. It is necessary to configure Tomcat with the location of the Apache SSL certificate, as described below.

  • Check that the certificate file is present at/opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pemand the certificate key file is present at/opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem.
  • Uncomment the following line in the/opt/bitnami/apache-tomcat/conf/server.xmlfile:
  • <Connector port="8443"
  • protocol="HTTP/1.1" SSLEnabled="true"
  • maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
  • enableLookups="false" disableUploadTimeout="true"
  • acceptCount="100" scheme="https" secure="true"
  • clientAuth="false" sslProtocol="TLS"
  • keystoreFile="conf/myKeystore"
  • keystorePass="your_password"
  • SSLCertificateFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem"
  • SSLCertificateKeyFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem"/>
  • Restart the Apache Tomcat server

You should now be able to access your Web applications over HTTPS by browsing to.

How To Create An SSL Certificate For Apache Tomcat?

A detailed guide is available in the official Apache Tomcat documentation at

How To Enable HTTPS Support With SSL Certificates?

NOTE: The steps below assume that you are using a custom domain name and that you have already configured the custom domain name to point to your cloud server.

Bitnami images come with SSL support already pre-configured and with a dummy certificate in place. Although this dummy certificate is fine for testing and development purposes, you will usually want to use a valid SSL certificate for production use. You can either generate this on your own (explainedhere) or you can purchase one from a commercial certificate authority.

Once you obtain the certificate and certificate key files, you will need to update your server to use them. Follow these steps to activate SSL support:

  • Use the table below to identify the correct locations for your certificate and configuration files.

Variable / Value
Current application URL /
Example: or
Apache configuration file / /opt/bitnami/apache2/conf/bitnami/bitnami.conf
Certificate file / /opt/bitnami/apache2/conf/server.crt
Certificate key file / /opt/bitnami/apache2/conf/server.key
CA certificate bundle file (if present) / /opt/bitnami/apache2/conf/server-ca.crt
  • Copy your SSL certificate and certificate key file to the specified locations.

NOTE: If you use different names for your certificate and key files, you should reconfigure theSSLCertificateFileandSSLCertificateKeyFiledirectives in the corresponding Apache configuration file to reflect the correct file names.
  • If your certificate authority has also provided you with a PEM-encoded Certificate Authority (CA) bundle, you must copy it to the correct location in the previous table. Then, modify the Apache configuration file to include the following line below theSSLCertificateKeyFiledirective. Choose the correct directive based on your scenario and Apache version:

Variable / Value
Apache configuration file / /opt/bitnami/apache2/conf/bitnami/bitnami.conf
Directive to include (Apache v2.4.8+) / SSLCACertificateFile "/opt/bitnami/apache2/conf/server-ca.crt"
Directive to include (Apache < v2.4.8) / SSLCertificateChainFile "/opt/bitnami/apache2/conf/server-ca.crt"
NOTE: If you use a different name for your CA certificate bundle, you should reconfigure theSSLCertificateChainFileorSSLCACertificateFiledirectives in the corresponding Apache configuration file to reflect the correct file name.
  • Once you have copied all the server certificate files, you may make them readable by the root user only with the following commands:
  • sudochownroot:root /opt/bitnami/apache2/conf/server*
  • sudochmod 600 /opt/bitnami/apache2/conf/server*
  • Open port 443 in the server firewall.Refer to the FAQfor more information.
  • Restart the Apache server.

You should now be able to access your application using an HTTPS URL.

How To Create An SSL Certificate?

OpenSSL is required to create an SSL certificate. A certificate request can then be sent to a certificate authority (CA) to get it signed into a certificate, or if you have your own certificate authority, you may sign it yourself, or you can use a self-signed certificate (because you just want a test certificate or because you are setting up your own CA).

Follow the steps below:

  • Generate a new private key:
  • sudoopensslgenrsa -out /opt/bitnami/apache2/conf/server.key 2048
  • Create a certificate:
  • sudoopensslreq -new -key /opt/bitnami/apache2/conf/server.key -out /opt/bitnami/apache2/conf/cert.csr

IMPORTANT: Enter the server domain name when the above command asks for the "Common Name".
  • Sendcert.csrto the certificate authority. When the certificate authority completes their checks (and probably received payment from you), they will hand over your new certificate to you.
  • Until the certificate is received, create a temporary self-signed certificate:
  • sudoopenssl x509 -in /opt/bitnami/apache2/conf/cert.csr -out /opt/bitnami/apache2/conf/server.crt -req -signkey /opt/bitnami/apache2/conf/server.key -days 365
  • Back up your private key in a safe location after generating a password-protected version as follows:
  • sudoopensslrsa -des3 -in /opt/bitnami/apache2/conf/server.key -out privkey.pem

Note that if you use this encrypted key in the Apache configuration file, it will be necessary to enter the password manually every time Apache starts. Regenerate the key without password protection from this file as follows:

sudoopensslrsa -in privkey.pem -out /opt/bitnami/apache2/conf/server.key

Find more information about certificates at

How To Force HTTPS Redirection?

Add the following to the top of the/opt/bitnami/apps/jenkins/conf/httpd-prefix.conffile:

RewriteEngine On

RewriteCond %{HTTPS} !=on

RewriteRule ^/(.*) [R,L]

After modifying the Apache configuration files:

  • Open port 443 in the server firewall.Refer to the FAQfor more information.
  • Restart Apache to apply the changes.

How To Debug Apache Errors?

Once Apache starts, it will create two log files at/opt/bitnami/apache2/logs/access_logand/opt/bitnami/apache2/logs/error_logrespectively.

  • Theaccess_logfile is used to track client requests. When a client requests a document from the server, Apache records several parameters associated with the request in this file, such as: the IP address of the client, the document requested, the HTTP status code, and the current time.
  • Theerror_logfile is used to record important events. This file includes error messages, startup messages, and any other significant events in the life cycle of the server. This is the first place to look when you run into a problem when using Apache.

If no error is found, you will see a message similar to:

Syntax OK

How To Change The Java Memory Settings?

The Java Virtual Machine (JVM) determines the default settings for your Java application:

JAVA_OPTS="-Xms256m -Xmx512m"

You can increase these Java settings for your application if necessary. The settings are in the/opt/bitnami/java/bitnami/setenv.shfile. Here is an example of how to change the memory settings:

export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx768M"

IMPORTANT: This file is a symlink to a configuration file that changes depending on the instance type that you are currently using. The symlink will be automatically changed when you resize your server.

How To Debug Errors In Tomcat?

The main Apache Tomcat configuration file is at/opt/bitnami/apache-tomcat/conf/server.xml.

Once Apache Tomcat starts, it will create several log files in the/opt/bitnami/apache-tomcat/logsdirectory. The main log file is thecatalina.outfile where you can find error messages. On some platforms, you may needrootaccount privileges to view these files.

How To Upload Files To The Server With SFTP?

Although you can use any SFTP/SCP client to transfer files to your server, the link below explains how to configure FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X). It is required to use your server's private SSH key to configure the SFTP client properly. Choose your preferred application and follow the steps in the link below to connect to the server through SFTP.

How to upload files to the server

How To Configure Slaves As Docker Containers?

By configuring your Bitnami Jenkins instance with containers as ephemeral slaves, you can run tests for specific languages on demand within a pre-configured and fully isolated environment. This method usesDockerwithBitnami containers.

You will need an instance of the Bitnami Jenkins Stack and administrator access to it.

Step 1: Prepare The Environment

  • Confirm that you have Docker installed:
  • sudodocker version

If Docker is not installed, install it usingthe instructions in the Docker documentation.

  • Allow the user running Jenkins to connect to the Docker daemon by adding it to thedockergroup:
  • sudousermod -aGdocker tomcat
  • sudo /opt/bitnami/ctlscript.sh restart

NOTE: By adding the usertomcatto the groupdocker, you are granting it superuser rights. This is a serious security issue not addressed in this guide. Please be aware of the risks before proceeding.
  • Check that you have the Docker Pipeline plugin installed. From the Jenkins administration panel, navigate to the "Manage Jenkins" section and click the "Manage Plugins" link. On the resulting page, select the "Installed" tab and look for "Docker Pipeline" or use the filter bar.

The plugin should be installed by default in Jenkins v2.x and may need to be manually installed in Jenkins v1.x.

Step 2: Configure A Job

Create a job that uses the Docker Pipeline plugin to build the application inside the container and ensure the container itself is created and destroyed when the job starts and finishes.

Follow these steps:

  • From the main panel, click "New Job".
  • Give the job a name and select "Pipeline" as the project type.

  • In the "Pipeline" tab, configure the pipeline using the fields below as reference. Replace GITHUB-REPO-URL and GITHUB-REPO-BRANCH with the GitHub repository URL and repository branch to be built.
  • Definition: Pipeline script from SCM
  • SCM: Git
  • Repository URL: GITHUB-REPO-URL
  • Branch specifier: GITHUB-REPO-BRANCH
  • Script path: Jenkinsfile

  • Save the job.

Step 3: Create The Pipeline Script

The Docker Pipeline plugin looks for a pipeline script containing build instructions. The script consists of a series of steps, is typically namedJenkinsfileand is stored as part of the source code repository.

As an example, this guide assumes that the Jenkins job uses a GitHub source code repository containing a PHP application with acomposer.jsonfile and a set of phpUnit tests. Here is a sampleJenkinsfilefor this example PHP application:

node {

stage("Main") {

checkoutscm

docker.image('bitnami/php-fpm:latest').inside("-e COMPOSER_HOME=/tmp/jenkins-workspace") {