I created a script bhanu.sh in that script i configure all the paths to access jenkins
Can you tell me where i done mistake or can you explain how to access jenking through java or systemd in detail?
I created a script bhanu.sh in that script i configure all the paths to access jenkins
I can see what went wrong here. You’re trying to run Java code inside a shell script (.sh), and that’s why you’re getting those “command not found” and “syntax error” messages. Shell scripts (bash) can’t interpret Java syntax like import or URL url = new URL(…).
If you want to use Java to interact with Jenkins, you’ll need to put that code inside a Java file, for example JenkinsTrigger.java, then compile and run it using:
javac JenkinsTrigger.java
java JenkinsTrigger
But if your goal is just to trigger Jenkins jobs or access Jenkins via CLI, you don’t actually need Java code — you can do it directly from bash using curl, like this:
curl -X POST http://localhost:8085/job/your-job/build
–user admin:Adm!n321
That will trigger your Jenkins job using basic authentication.
So basically:
Use .java files for Java code (not .sh).
Use shell + curl if you just want to automate Jenkins tasks.
Hope that clears it up a bit! You’re on the right track — just need to separate the scripting and Java parts.