Step 5: Grant permissions to the jenkins user to execute sudo commands without needing to enter a password.
#!/bin/bash
sudo apt install openjdk-17-jdk -y
java --version
wget -p -O - https://pkg.jenkins.io/debian/jenkins.io.key | apt-key add -
sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5BA31D57EF5975CA
apt-get update
apt install jenkins -y
systemctl start jenkins
ufw allow 8080
IP_Of_Jenkins_server jenkins.phanhuy.tech
IP_Of_Jenkins_server jenkins.phanhuy.tech
Create conf.d/jenkins.phanhuy.tech.conf at /etc/nginx
server {
listen 80;
server_name jenkins.elroydevops.tech;
location / {
proxy_pass http://jenkins.phanhuy.tech:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install -y dotnet-sdk-8.0
Visit the official ngrok website: ngrok.com
ngrok authtoken YOUR_AUTH_TOKEN
ngrok http http://jenkins.phanhuy.tech:8080
Add new node at Dashboard/Manage Jenkins/Nodes with the Launch method set to 'Launch agent by connecting it to the controller'
echo your_secret_key > secret-file
curl -sO http://your_url/jnlpJars/agent.jar
http://jenkins.phanhuy.tech:8080/ -secret @secret-file -name your-node-label -webSocket -workDir "your-path" > nohub.out 2>&1 &
sudo nano /etc/systemd/system/smswebapp.service
Description=SMS Web App
After=network.target
[Service]
WorkingDirectory=/var/lib/jenkins/workspace/DotNetCorePipeline/smswebapp/bin/Debug/net8.0
ExecStart=/usr/bin/dotnet /var/lib/jenkins/workspace/DotNetCorePipeline/smswebapp/bin/Debug/net8.0/smswebapp.dll
Restart=always
TimeoutStopSec=20
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
Create and configure a reverse proxy for the web server similar to that of the Jenkins server with port 8080.
sudo nano /etc/nginx/sites-available/smswebapp
📌Step 5: Grant permissions to the jenkins user to execute sudo commands without needing to enter a password.
Depending on which sudo commands are used in the Jenkins file, grant additional permissions to the jenkins user to use those sudo commands without needing to enter a password.
sudo visudo
jenkins ALL=(ALL) NOPASSWD: /usr/bin/dotnet*
jenkins ALL=(ALL) NOPASSWD: /bin/systemctl daemon-reload
jenkins ALL=(ALL) NOPASSWD: /bin/systemctl restart smswebapp
jenkins ALL=(ALL) NOPASSWD: /bin/systemctl start smswebapp
jenkins ALL=(ALL) NOPASSWD: /bin/systemctl stop smswebapp