Jenkins how to start service Postfix mail server

In this tutorial, I using Jenkins how to start/stop/ status service Postfix mail server. Jenkins the essential for DevOps Roles. Now, let’s go use jenkins start service Postfix mail server.

Note:  To start or stop service Postfix then account Jenkins setting in sudoers option “NOPASSWD” as the picture below

Jenkins how to start service Postfix mail server 05

How to start service Postfix mail server use Jenkins

Create job “start_stop_postfix” “Freestyle project” as picture below

Jenkins how to start service Postfix mail server

In General tab, Select “This project is parameterized” with “Choice Parameter” as the picture below

Jenkins how to start service Postfix mail server 02

In Build tab, you select  “Execute shell” to written bash script “start/stop/status postfix” as the picture below

Jenkins how to start service Postfix mail server 03

My code bash script

set +e
f_postfix() {
  sudo postfix $1
  echo $?
}
whoami
if [ $COMMAND == "status" ]
then
  f_postfix $COMMAND

  if [ $? -ne 0 ]
  then
    echo "Postfix not running"
  else
    echo "Postfix Running"
  fi
fi
if [ $COMMAND == "start" ]
then
  f_postfix $COMMAND
  if [ $? -ne 0 ]
  then
    echo "Postfix start Not Success"
  else
    echo "Postfix start Success"
  fi
fi
if [ $COMMAND == "stop" ]
then
  f_postfix $COMMAND
  if [ $? -ne 0 ]
  then
    echo "Postfix stop Not Success"
  else
    echo "Postfix stop Success"
  fi
fi

The finish, you click “Build with Parameters” to build job. You can select COMMAND “status or start or stop” to Build as the picture below

Jenkins how to start service Postfix mail server 04

Conclusion

Thought the article, you can use Jenkins how to start service Postfix mail server as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.