Home > front end >  How to add a directory to the bitbucket pipline environment?
How to add a directory to the bitbucket pipline environment?

Time:05-31

I have a spring boot project that uses bitbucket pipelines for its CI/CD deployment.

It was working fine until I added a react front end to bundle with the project.

I added this to my pom.xml

<plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <copy todir="${project.build.directory}/classes/public">
                                    <fileset dir="${project.basedir}/ob-frontend/build"/>
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

and now the pipeline fails with

[INFO] --- frontend-maven-plugin:1.12.1:npm (npm install) @ scienta ---
[INFO] Running 'npm install' in /opt/atlassian/pipelines/agent/build/ob-frontend
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.360 s
[INFO] Finished at: 2022-05-29T11:06:17Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.1:npm (npm install) on project scienta: Failed to run task: 'npm install' failed. java.io.IOException: /opt/atlassian/pipelines/agent/build/ob-frontend doesn't exist. -> [Help 1]

I understand that the new plugin creates a new directory, and the bitbucket pipeline env isn't doing that, I'm unsure how to tell the pipeline to do that.

CodePudding user response:

It looks like it didn't even get to executing your maven-antrun-plugin task because it's the frontend-maven-plugin which fails.

Running 'npm install' in /opt/atlassian/pipelines/agent/build/ob-frontend
...
/opt/atlassian/pipelines/agent/build/ob-frontend doesn't exist

Here /opt/atlassian/pipelines/agent/build must be the ${project.basedir} when it's cloned to the build agent filesystem (since you expect the results of the frontend build be available in ${project.basedir}/ob-frontend/build). So the error says the frontend source directory ${project.basedir}/ob-frontend doesn't exist for some reason.

Regarding your question on creating directories during build, there's an mkdir Ant task, which can be configured like so:

<configuration>
    <target>
        <mkdir dir="${basedir}/target/some-dir" />
        ...
    </target>
</configuration>

CodePudding user response:

This answer helped me fix my issue: https://stackoverflow.com/a/35498001/4831652 I wrapped the plugins in my pom.xml with

<pluginManagement>...</pluginManagement>
  • Related