I'm creating a build job within the Jenkins CI/CD software. The build job will clone my android project from Github and generates the APK. I'm using Ubuntu 20.04 LTS server OS.
As part of the build step, I'm executing the following command via Jenkins:
rm -r app/src/main/java/in/myproj/utils/Constants.kt But receiving the following error:
/tmp/jenkins10737829520192897047.sh: 1: Syntax error: "in" unexpected It looks like the bash is treating the folder name in as a Constant. I have been trying to find a solution since morning today but failed miserably. Any help is greatly appreciated.
Edit:
I have debugged the issue further and found the actual cause. It is not the rm command that is failing. I have another build step where I'm appending some code snippets to a file. The following is the code snippet that is actually failing:
cat << EOT >> app/src/main/java/in/myproj/utils/Constants.kt "package `in`.myproj.utils class Constants { companion object { const val BASE_URL = "https://api.example.in/api/" const val BASE_URL_IMAGE_ADDRESS = "https://dashboard.example.in:5555/" const val BASE_URL_PROFILE_IMAGE_ADDRESS = "https://api.example.in/" const val ABOUT_US_URL = "https://example.in/aboutus.html" const val PRIVACY_POLICY_URL = "https://example.in/privacy-policy.html" const val TERMS_AND_CONDITIONS_URL = "https://example.in/terms-condition.html" const val REQUEST_TIMEOUT_DURATION = 10 const val STATUS_SUCCESS = 1
cat -v your_script.sh?rm -r app/src/main/java/in/myproj/utils/Constants.ktis the entire script. When I execute it via terminal directly, it works fine. It fails only when I execute it via Jenkins.cat -v /tmp/jenkins10737829520192897047.sh? And how does Jenkins execute it? Does it help if you add a shebang line (#!/bin/sh) to the top of your script?