gpt4 book ai didi

Runing a command on a local folder with Jenkins(使用Jenkins在本地文件夹上运行命令)

转载 作者:bug小助手 更新时间:2023-10-28 09:51:24 24 4
gpt4 key购买 nike



I have this folder structure:

我有这样的文件夹结构:



  • /home/user/project

    • common

    • web

    • mobile




I would like to run yarn test in every on this folders in parallel and I would like to use Jenkins (or something else?) to have an easy to use user interface

我想在每个文件夹上并行运行纱线测试,我想使用Jenkins(或其他什么?)拥有易于使用的用户界面


is it possible ?

有可能吗?


I use the nodeJS plugin in a freestyle project.
I install nodejs like this :
enter image description here
Then I try to do this :
enter image description here
then I have this error:
enter image description here

我在一个自由式项目中使用NodeJS插件。我这样安装NodeJS:然后尝试这样做:然后出现以下错误:


Looks like yarn is not installed... but it should be installed because I put yarn as a global packages

看来纱线没有安装..。但它应该是安装的,因为我把纱线作为全球包


Any ideas ?

有什么好主意吗?


更多回答
优秀答案推荐

I noticed that the issue you're encountering may be related to a specific problem discussed in this Stack Overflow post: How to enable Yarn for Jenkinsfile Pipeline syntax?

我注意到你遇到的问题可能与这篇Stack Overflow文章中讨论的一个特定问题有关:如何为Jenkinsfile Pipeline语法启用Yarn?


Based on my assessment, the error you're facing appears to be associated with Yarn not being configured as an environment variable within your Jenkins setup, which could result in it not being injected correctly during job execution (in my opinion).

根据我的评估,您面临的错误似乎与Yarn没有被配置为Jenkins设置中的环境变量有关,这可能导致在作业执行期间没有正确地注入它(在我看来)。


To address this, I recommend considering the use of the NPM and Yarn Wrapper and Steps plugin. It's a straightforward solution, check all the details at https://plugins.jenkins.io/npm-yarn-wrapper-steps/ to configure and could potentially resolve the issue you're facing. I encourage you to give it a try to see if it aligns with your requirements. The plus is that you can use on a GUI Job or pipeline (best solution for me).

为了解决这个问题,我建议考虑使用NPM和Yarn包装器以及STEPS插件。这是一个直截了当的解决方案,请查看https://plugins.jenkins.io/npm-yarn-wrapper-steps/上的所有详细信息进行配置,并可能解决您面临的问题。我鼓励您试一试,看看它是否符合您的要求。优点是您可以在图形用户界面作业或流水线上使用(对我来说是最好的解决方案)。



If you want to run the command across three folders in parallel, it makes more sense to create a declarative pipeline and use the parallel command docs. Your code would look like this:

如果您希望在三个文件夹中并行运行该命令,创建声明性管道并使用并行命令文档会更有意义。您的代码将如下所示:


pipeline {
agent any
stages {
stage('Run Tests') {
parallel {
stage('Common') {
steps {
dir(/home/user/project/common) {
sh "yarn test"
}
}
}
stage('web') {
steps {
dir(/home/user/project/web) {
sh "yarn test"
}
}
}
stage('mobile') {
steps {
dir(/home/user/project/mobile) {
sh "yarn test"
}
}
}
}
}
}
}

This will trigger yarn test across all three directories at once. As for the installation, just make sure you have nodeJs and yarn installed on your Jenkins machine and it should work without having to use plugins.

这将同时在所有三个目录中触发纱线测试。至于安装,只需确保您的Jenkins机器上安装了NodeJS和Snow,并且它应该可以在不使用插件的情况下运行。


更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com