I am trying to execute following maven command from jenkins job,
mvn clean install sonar:sonar -Dsonar.host.url=http://hostname:9095/sonar -Dsonar.projectKey=mavensam
I think it's giving you the error because the program can't hit the endpoint you specified.
You shouldn't be specifying the port if the URL already has a DNS mapping. For example, if http://sonar.yourcompany.com is already mapped to 123.23.22.10:9000
So your -Dsonar.host.url flag should be: -Dsonar.host.url=http://sonar.yourcompany.com
You don't need the /sonar at the end of http://sonar.yourcompany.com
Also, sonar runs on port 9000, not 9095.