3

I have a react project that I configured on Gitlab CICD Pipeline (with docker). In my pipeline, I have a step for create the package that use frontend-maven-plugin plugin (Packaging)

Each time I run the pipeline all artifact are download. I want to use a cache in the pipeline but the configuration below doesn't work. I think that frontend-maven-plugin use a different location for cache.

How can I configure it ?

The pipeline Gitlab :

stages:
  - build
  - analyse
  - package
  - deploiement

cache:
  paths:
    - project_front/projectdir/node_modules/

variables:
  MAVEN_CLI_OPTS: "-s ${MAVEN_PROJECT_SETTINGS} --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=${MAVEN_PROJECT_REPO}"

#
# Build de l'application
Build:
  image: maven:3.5.2-jdk-8
  stage: build
  tags: [ 'project' ]
  script:
    # Récupération de la version du projet maven
    - mvn $MAVEN_CLI_OPTS -U  clean install -D maven.test.skip=true

#
# Step d'analyse SONAR
Qualimétrie:
  image: maven:3.5.2-jdk-8
  stage: analyse
  tags: [ 'project' ]
  script:
    - mvn  $MAVEN_CLI_OPTS -P sonarqubeproject,jacoco,nexus -U -D sonar.qualitygate.wait=true -D sonar.branch.name=$CI_COMMIT_BRANCH verify sonar:sonar
  artifacts:
    when: always
    reports:
      junit:
        - "*/target/surefire-reports/TEST-*.xml"

#
# Génération du package de livraison
Packaging:
  image: maven:3.5.2-jdk-8
  stage: package
  tags: [ 'project' ]
  script:
    # Packaging
    - mvn $MAVEN_CLI_OPTS -P package_livraison -U  package -Dmaven.test.skip=true  -D HTTP_PROXY=${PROXY_SRV} -D HTTPS_PROXY=${PROXY_SRV}
  artifacts:
    paths:
      - '**/target/*.tar.gz'

#
# Step de déploiement Ansible
Deploiement INT:
  stage: deploiement
  tags: [ 'project' ]
  image: ansible/centos7-ansible
  only:
    - master
    - develop
    - feature-gitlab-cicd
  when: manual
  dependencies:
    - Packaging
  script:
    #Installation de XMLLINT pour récupérer la version dans le POM
    - yum -y install libxml2
    # Récupération de la version du projet maven
    - VERSION_PROJECT=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml`
    # Execution du ssh-agent
    - eval $(ssh-agent -s)
    # Récupération de la clé privée de l'hote et envoi dans le container
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    # Création des répertoires
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    # Recherche de l'hote
    - ssh-keyscan myhost >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    # Envoi du package à la machine PROJECT
    - cp project_deploiement/target/*.tar.gz /home/gitlab-runner/depot/
    #Lancement du playbook
    - ansible-playbook -v -i project_ansible/project-hosts project_ansible/ansible/project-install-playbook-int.yml -f 10 --extra-vars "project_version=${VERSION_PROJECT} -vvvv"

profile :

 <profile>
            <id>package_livraison</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>${frontend-maven-plugin.version}</version>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${frontend-src-dir}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>install-frontend-tools</id>
                                <goals>
                                    <goal>install-node-and-yarn</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>yarn-install</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <!-- Le proxy maven n'est pas utilisé, on le redéfinit-->
                                    <yarnInheritsProxyConfigFromMaven>true</yarnInheritsProxyConfigFromMaven>
                                    <arguments>install</arguments>

                                </configuration>
                            </execution>
                            <execution>
                                <id>build-frontend</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <arguments>build</arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

Properties :

<properties>
    <frontend-src-dir>./projectdir</frontend-src-dir>
    <node.version>v10.15.3</node.version>
    <yarn.version>v1.15.2</yarn.version>
    <frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>
</properties>

The directory Structure

enter image description here

Broshet
  • 133
  • 12

0 Answers0