BitBucket Pipelines Gradle build

Patrick Farwick January 11, 2017

Hi,

 

I'm wondering how to build a Java code repository with Gradle using Bitbucket pipelines.

I've currently got this code, but the build is always failing:

 

# This is a sample build configuration for Gradle.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: java:8

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - gradlew --version
          - gradlew build

 

I've also have the gradlew.bat and gradlew file in my repository and in the folder gradle under wrapper the gradle-wrapper.jar (and some scripts to be executed from the build.gradle).

Because I want to try Bitbucket pipelines on my Minecraft Mod out, gradle would also have to download some stuff to be able to compile the src code.

Currently it works all well on my local Windows machine, but on Bitbucket I'm getting the following error:

bash: gradlew: command not found


Thx in advance.

2 answers

1 accepted

2 votes
Answer accepted
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 11, 2017

Hey @MinecraftPlaye,

The gradlew is a script so you will need to execute it like a script.

Try:

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - ./gradlew --version
          - ./gradlew build

Let me know how that goes

Patrick Farwick January 12, 2017

Sadly, it does not work:

bash: ./gradlew: Permission denied

Hm, wat I'm wondering, if it dienies me the permission to do that, will it denie me the permission to change a file with the gradlew setup (actually, after building it increases the version number automatically in the build.properties file wink )

Patrick Farwick January 12, 2017

Hi,

I just did some changes after some research: I added the bash keyword before every single of the two commands and now it's working. wink

Like Brijesh Joshi likes this
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 12, 2017

Great to hear it's working! smile

Another workaround for the permission denied is to commit the gradlew file with executable permissions. 

http://stackoverflow.com/questions/17668265/gradlew-permission-denied

To make a file executable in Windows maybe try http://stackoverflow.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows

Kashif-Ur-Rehman January 23, 2017

Hello,

Here is my gradle script, to build and create EAR file for my project.

# You can specify a custom docker image from Docker Hub as your build environment.
image: qlik/gradle
 
pipelines:
  default:
    - step:
        script:
         
          - gradle clean
          - gradle test
          - gradle ear




Previously above script was working perfect (i was getting my ear ) from last two months , but today when i start build, it fails on clean command i.e

gradle clean 

+ gradle clean/tmp/bashScript853752692724365978.sh: line 22: gradle: command not found+ gradle clean/tmp/bashScript853752692724365978.sh: line 22: gradle: command not found

 

Can any body help me ? 

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2017

@Kashif-Ur-Rehman can you rerun that Pipeline? Is that issue still occurring?

Kashif-Ur-Rehman January 31, 2017

@Philip Hodder, yes , i rerun this yesterday and today, and now it is working fine.
I dont know reason, that why same script was not running previous week ..

Do you have any idea ? 

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 1, 2017

My apologies @Kashif-Ur-Rehman. That was a bug that we accidentally introduced into the system last week. Specifically, we made a change to the way that we mount volumes inside the Docker container of your pipeline. We were able to detect, revert, and fix the issue before it was exposed to most of our users, but you seem to have unfortunately been affected by it.

Your script itself was not the problem and you should not encounter this issue anymore. smile

Kashif-Ur-Rehman February 1, 2017

Oh I see, BTW, previous week I was changing my script with different docker images, I thought may be docker image got change, but it was not.

Any how, thanks for detailed explanation. 

Malte Hübner February 13, 2017

Im am also experiencing this issue in some of our Pipeline branches:

/opt/atlassian/pipelines/agent/tmp/bashScript2757741404473080195.sh: line 16: grails: command not found

Is there a way how I can fix this by myself @Philip Hodder?  

 

 

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 16, 2017

It should be fixed for you too now. But if not (let me know if you're still seeing it), installing dependencies (such as grails) as part of you pipeline, or burning them inside your Docker image, should be a sufficient work around.

0 votes
Salex August 23, 2022

Hello everybody!

I've recently gotten the same issue. 3 weeks ago my pipeline was working and now it throws an error message "bash: gradle: command not found".  @Philip Hodder is this problem similar to the previous ones?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events