Automating Package Installations with Jenkins
1. Introduction
The Nautilus DevOps team at Stratos Datacenter required an automated solution for installing and configuring packages on their storage server (ststor01
). This article details the process of creating and configuring a Jenkins job, named install-packages
, to fulfill this requirement, utilizing the Publish Over SSH plugin for remote execution.
2. Prerequisites
- Access to Jenkins UI (URL provided by the lab environment).
- Jenkins admin credentials:
username: admin
,password: Adm!n321
. - Storage server (
ststor01
) credentials:username: natasha
,password: Bl@kW
. -
Publish Over SSH
Jenkins plugin installed and configured.
3. Step-by-Step Implementation
3.1. Access Jenkins and Initial Login
- Open the Jenkins UI by clicking the Jenkins button in the top bar or navigating to the provided Jenkins URL.
- Log in using the administrative credentials:
-
Username:
admin
-
Password:
Adm!n321
-
Username:
3.2. Configure Publish Over SSH Plugin for Remote Connectivity
The core of this task involves executing commands on a remote server (ststor01
). The Publish Over SSH
plugin facilitates this. The initial setup requires configuring the connection details for the target storage server, including its authentication.
Navigate to Manage Jenkins > Configure System.
Scroll down to the Publish over SSH section.
Click the "Add" button under SSH Servers.
Fill in the details for the
ststor01
storage server:
Name: ststor01
(or a descriptive name like Nautilus_Storage
)
Hostname: ststor01.stratos.xfusioncorp.com
(as per infrastructure details)
Username: natasha
(as per infrastructure details)
Remote Directory: /tmp
(a common temporary directory)
5.Enable Password Authentication:
- Click the "Advanced..." button to expand further options for the
ststor01
entry. - Check the box: "Use password authentication, or use a different key".
- In the Passphrase / Password field that appears, enter the password:
Bl@kW
(from infrastructure details).
6.Click the "Test Configuration" button for the ststor01
server. It should display "Success".
7.Click "Apply" and then "Save" at the bottom of the Configure System page.
3.3. Create the install-packages
Jenkins Job
From the Jenkins Dashboard, click "New Item" on the left-hand navigation pane.
Item Name: Enter
install-packages
.Type: Select "Freestyle project".
Click "OK".
3.4. Configure Job Parameters
To make the job flexible, a string parameter will be added to allow users to specify which package to install.
1.In the job configuration page, check the box: "This project is parameterized".
2.Click "Add Parameter" and select "String Parameter".
Name: PACKAGE
Default Value: net-tools
(or httpd
, git
for initial testing)
Description: The name of the package to install on the storage server.
3.5. Configure the Build Step for Remote Execution
This is where the actual package installation command is defined, using the previously configured SSH connection.
Scroll down to the "Build" section of the job configuration.
Click "Add build step" and select "Send files or execute commands over SSH".
SSH Server: Select
ststor01
(or the name you assigned) from the dropdown list.-
In the "Exec command" textarea, enter the following shell script. This script passes the
natasha
user's password tosudo
usingsudo -S
, which is crucial for privilege elevation onststor01
.
#!/bin/bash # Define the password for sudo escalation (sensitive, but necessary for automation via script) PACKAGE_PASSWORD="Bl@kW" echo "Starting installation of package: $PACKAGE on ststor01..." # Use 'echo $PACKAGE_PASSWORD | sudo -S' to pass the password to sudo # The '-S' flag tells sudo to read the password from standard input. # 'yum install -y' is used for CentOS/RHEL systems (like ststor01) to install packages. echo $PACKAGE_PASSWORD | sudo -S yum install -y $PACKAGE # Check the exit code of the 'yum install' command if [ $? -eq 0 ]; then echo "SUCCESS: Package '$PACKAGE' installed successfully." else echo "FAILURE: Package '$PACKAGE' installation failed. Check server logs." exit 1 fi
5.Click "Save" at the bottom of the job configuration page.
4. Testing and Verification
After configuring the job, it's essential to test its functionality and reliability.
Navigate to the
install-packages
job page.Click "Build with Parameters" on the left menu.
In the PACKAGE field, enter a package name that is likely not installed (e.g.,
git
,htop
).Click "Build".
Monitor the build in the Build History section. Once it completes, click on the build number (e.g.,
#1
) and then select "Console Output".Verify that the console output displays
SUCCESS: Package '...' installed successfully.
andFinished: SUCCESS
.
7.Run the job again with a different package (e.g., net-tools
) to confirm the job's reliability and repeated successful execution. This ensures the configuration is robust.
5. Conclusion
By following these steps, a robust Jenkins job named install-packages
has been successfully created. This job automates the process of installing specified packages on the ststor01
storage server within the Stratos Datacenter infrastructure, significantly improving operational efficiency for the Nautilus DevOps team. The use of the Publish Over SSH
plugin combined with parameterized builds offers a flexible and secure way to manage remote package installations.
Top comments (0)