This article will helps you to upgrade from Windows Server 2012 to Windows Server 2016. If you need to keep the same hardware & all the server roles you have already setup without flattening the server, you will want to do an in-place upgrade. In-place upgrades permit you to go from an older OS to a newer one while keeping your settings, server roles, & data intact.
To upgrade to Windows Server 2019, use this topic first to upgrade to Windows Server 2016, and then upgrade windows server 2016 to 2019.
Before you begin your in-place upgrade
Before you began upgrade Windows Server, we suggest that you collect some information from your server, for diagnostic and troubleshooting purposes. Through this intelligence is purpose for use only if your upgrade fails, please make sure that you have store the information somewhere that you can get to it off of your device.
To collect your info
1- Run a command prompt, go to c:Windowssystem32, and then type systeminfo.exe.
Copy, paste & store the resulting system information somewhere off of your device.

2- Type ipconfig /all, and then copy & paste the resulting configuration information into the same location as above.

After you have collected all the Windows Server-related information, we highly recommend that you take backup of your operating system, apps, and virtual machines. You can’t have any VM (virtual machines) running during the in-place upgrade.
Upgrade Windows Server 2012 to Server 2016
1- Please make sure that you are running Windows Server 2012. Right click on my computer (This PC) and then properties

2- Enter Windows Server 2016 Setup media, and then double-click to run.

3—It is always best practice to get the latest updates in case any important security patches have been released, so I recommend keeping the default setting. Click next.

4- Checking the updates.

5- Enter your Server 2016 Product Key and then click next.

6- Here, you can decide what operating system you want to upgrade, and click next.

7- Accept the license terms.

8- In this window, the Keep personal files and apps default option was chosen, so I cannot advise on the impact of choosing anything. I would imagine that selecting this would delete everything, including any installed Server Roles. Proceed with this step at your own risk. Click next

9- Here, you will get a rather lengthy Getting Updates window.

10- Finally, before starting the installation, you are prompted with an interesting warning, which you have to dismiss (confirm) before the installation starts.

11- The installation checks disk space.

12- Now the critical moment, review the settings that we have specified and then select Install to start the process:

13- The full-screen setup will start, preventing you from doing anything else on the Server throughout the process.

14- This Server will restart several times after that. It will take some time to complete the whole process.

15- After the upgrade, you will be greeted with the new Windows Server 2016 login screen.

Watch Video: How to upgrade Windows Server 2012 to Server 2016.
For more details, please visit Microsoft
Related: Upgrade Windows Server 2008 r2 to 2012