My First Beginner Freestyle Project -Challenges and Troubleshooting
Now, We have created the foundation where successfully setting up Jenkins on an EC2 Ubuntu server, the next step was to connect Jenkins with a GitHub repository and automate the execution of a Java program using a Freestyle project.
The idea was simple: whenever Jenkins runs the job, it should pull the Java code from GitHub, compile it, and execute it automatically.
The first step was creating a GitHub repository containing a simple Java program. After pushing the code to GitHub, I created a Freestyle Project in Jenkins and configured the Source Code Management section to use Git. I added the repository URL and selected the branch (*/main) so Jenkins could clone the repository during the build process.
One of the first issues I faced was that Jenkins could not clone the repository because Git was not installed on the EC2 server. When Jenkins tried to fetch the code, the job failed with an error related to the Git executable.
The fix was simple: install Git on the server using sudo apt install git, then restart Jenkins.
Another problem occurred while saving the project configuration. Jenkins displayed the error “HTTP ERROR 403 – No valid crumb was included in the request.” This was related to Jenkins’ CSRF security protection. Since the Jenkins server was running on a public cloud instance, the client IP sometimes changed due to network routing, which caused the crumb token validation to fail.
The solution was to enable proxy compatibility or configure Jenkins to exclude the client IP from crumb validation and then restart the Jenkins service.
The most frequent task is reloading the Jenkins page to reflect new changes, ensuring a smoother process. I recommend selecting an EC2 server with adequate memory to minimize delays.
And one more issue i faced jenkins config.xml sudo nano /var/lib/jenkins/config.xml
click Ctrl + W and Search for
Add This Section Above
<crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer">
<excludeClientIPFromCrumb>true</excludeClientIPFromCrumb>
</crumbIssuer>
It should look like this:
</views>
<crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer">
<excludeClientIPFromCrumb>true</excludeClientIPFromCrumb>
</crumbIssuer>
</hudson>
This tells Jenkins to ignore client IP mismatch when generating crumb tokens
Save the file click on Ctrl+X and Y and then enter.
ProTip: Always restart the jenkins because it get updated with latest changes.
Run these commands:
sudo systemctl daemon-reload
sudo systemctl restart jenkins
Wait about 30–40 seconds. And Login to Jenkins always newly so it does not make any interruptions.
After fixing that, Jenkins was able to access the GitHub repository, but the Java program still did not run. The issue turned out to be related to the build step configuration. In the Freestyle project settings, I had to add a build step using Execute Shell and specify the commands to compile and run the Java program.
The correct commands looked like this:
javac HelloWorld.java
java HelloWorld
Another small issue appeared when Jenkins could not find the Java compiler. This happened because Java was not properly installed on the EC2 instance. Installing OpenJDK (sudo apt install openjdk-17-jdk) solved the problem, and the java -version command confirmed that Java was available.
Network configuration also created a minor obstacle. Initially, Jenkins was not accessible from the browser because port 8080 was not open in the EC2 security group. After adding an inbound rule allowing traffic on port 8080, the Jenkins dashboard became accessible through the public IP.
Once these issues were resolved, the pipeline worked smoothly. Jenkins successfully cloned the GitHub repository, compiled the Java program, and executed it automatically whenever the job ran. The console output displayed the result of the Java program, confirming that the CI automation was working as expected.
This process highlighted an important lesson: setting up automation tools often involves troubleshooting infrastructure, permissions, dependencies, and network configurations.
