<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.intersult</groupId> <artifactId>reactjs-test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>${project.artifactId}</name> <description>ReactJS Test</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.12.1</version> <executions> <execution> <id>install-node-and-npm</id> <goals> <goal>install-node-and-npm</goal> </goals> </execution> <execution> <id>npm-install</id> <goals> <goal>npm</goal> </goals> </execution> <execution> <id>npm-build</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run build</arguments> </configuration> </execution> </executions> <configuration> <nodeVersion>v18.8.0</nodeVersion> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.3.2</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <webResources> <resource> <directory>build</directory> </resource> </webResources> </configuration> </plugin> </plugins> </build> </project>
<plugin> <groupId>org.orienteer.jnpm</groupId> <artifactId>jnpm-maven-plugin</artifactId> <version>1.5</version> <executions> <execution> <?m2e execute onConfiguration?> <phase>generate-resources</phase> <goals> <goal>install</goal> </goals> <configuration> <registryUrl>https://registry.npmjs.org/</registryUrl> <strategy>ONE_DUMP</strategy> <outputDirectory>${project.build.directory}/generated-resources/jnpm/</outputDirectory> <pathPrefix>META-INF/resources</pathPrefix> <serverId>npmjs</serverId> <packages> <package>hello-world-server</package> </packages> <useCache>false</useCache> </configuration> </execution> </executions> </plugin>
Hinweis: Nach dem Speichern der Konfiguration scheint erst einmal gar nichts passiert zu sein. Die Installation von NodeJS und NPM ist jedoch Bestandteil eines entsprechenden Build-Prozesses und findet später an dieser Stelle statt.
pipeline { agent any stages { stage('Checkout') { steps { script { currentRevision = checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'dynarocks.com', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://dynarocks.com/svn/com.intersult/trunk/com.intersult/internal/work/reactts-test']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } } } stage('Install') { steps { nodejs(nodeJSInstallationName: 'NodeJS') { sh 'npm install' } } } stage('Generate Sources') { steps { nodejs(nodeJSInstallationName: 'NodeJS') { sh 'npm run generate' } } } stage('Build') { steps { nodejs(nodeJSInstallationName: 'NodeJS') { sh 'npm run build' } } } } }
Zunächst muss das Plugin "Docker Pipeline" installiert sein.
In Jenkins verwalten -> Konfiguration der Hilfsprogramme wird das Plugin konfiguriert.
Zuletzt kann eine Pipeline wie folgt erzeugt werden:
pipeline { agent { docker { image 'node:18.8.0-alpine3.16' } } stages { stage('Test') { steps { sh 'node --version' } } } }
https://www.jenkins.io/doc/book/pipeline/docker/
echo -n 'admin:admin123' | openssl base64
Die Zeile in .npmrc sieht dann so aus:
registry=[...] _auth=YWRtaW46YWRtaW4xMjMNCg==
https://help.sonatype.com/repomanager2/node-packaged-modules-and-npm-registries
import express from "express"; import {createProxyMiddleware} from "http-proxy-middleware"; import webpack from "webpack"; import middleware from "webpack-dev-middleware"; import options from "./webpack.config"; const host = "localhost", port = 8090; const server = express(); const compiler = webpack(options); server.use("/", middleware(compiler)); server.use(createProxyMiddleware("/service/**", { target: "http://localhost:8080" })); server.listen(port, () => { console.log("Server listening at http://" + host + ":" + port + "/"); });