如何让詹金斯将工件复制到动态目录?
我试图让 Jenkins 使用 scp 插件将构建的工件复制到另一台服务器上的存档目录。
理想情况下,我希望能够根据构建版本使目标是动态的,因此结果会像 /builds/
对于像 1.2 这样的构建版本。 3.4 它看起来像:
/builds/1.2.3.4/
从阅读 scp 插件页面来看,这看起来不可能,但我认为这里有人可能已经弄清楚了。
有办法做到这一点吗?
将版本号嵌入到文件名中的工件放在一个目录中是不是更好?
I'm trying to get Jenkins to copy the artifacts of a build to an archive directory on another server using the scp plugin.
Ideally, I'd like to be able to have the destination be dynamic based on the build version so the result would like something like /builds/<build version>/
For a build version like 1.2.3.4 it would look like:
/builds/1.2.3.4/
From reading the scp plugin page, it doesn't look like this is possible but I figured someone here may have figured it out.
Is there a way to do this?
Is it better to just put the artifacts with the version number embedded in the file name in one directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像你说的,我不认为 scp 插件可以直接做到这一点。然而,可能有一个解决方法。
在您的版本中,您可以使用 $BUILD_NUMBER(或 %BUILD_NUMBER%,视情况而定 -> Linux 与 Windows)访问版本号。
无论如何,作为脚本的一部分,您可以创建一个以 $BUILD_NUMBER 作为名称的目录,因此:
mkdir -p $BUILD_NUMBER
-or-
md %BUILD_NUMBER%
因此,例如,新目录将是 /path/to /workspace/1.2.3.4
构建完成后,在脚本末尾创建上述目录,将工件移入其中,然后 tar/zip 目录。
使用此 tar/zip 文件作为您的工作工件。
使用 scp 插件将此工件传输到您的目标计算机,并在那里解压/解压它(假设在 /path/to/artifact/directory 处),
然后您将得到 /路径/to/artifact/directory/1.2.3.4。
对于下一个构建,假设是 1.2.3.5,您将创建一个新目录(名为 1.2.3.5),在构建结束时将您的工件移入该目录,将其压缩并传输。
当您在目的地解压缩它时,您将有一个新目录 /path/to/artifact/directory/1.2.3.5 ,其中包含新构建的工件。
我知道这听起来很混乱,但实际上很容易实现。
Like you said, I don't think the scp plugin can do it directly. However, there may be a workaround.
In your build, you have access to the build number using $BUILD_NUMBER (or %BUILD_NUMBER%, as the case may be -> Linux vs Windows).
In any case, as part of your script, you could create a directory with $BUILD_NUMBER as the name, so:
mkdir -p $BUILD_NUMBER
-or-
md %BUILD_NUMBER%
So, for example, a new directory would be /path/to/workspace/1.2.3.4
Once your build is complete, at the end of your script, create the above directory, move your artifact into it, and tar/zip the directory up.
Use this tar/zip file as your job's artifact.
Use the scp plugin to transfer this artifact to your destination machine, and untar/unzip it there (let's say at /path/to/artifact/directory)
What you will have then, is /path/to/artifact/directory/1.2.3.4.
For the next build, let's say 1.2.3.5, you will create a new directory (named 1.2.3.5), move your artifact into it at the end of the build, zip it up and transfer it.
When you unzip it at your destination, you'll have a new directory /path/to/artifact/directory/1.2.3.5 with the new build's artifact in it.
I know it sounds confusing, but is actually quite easy to implement.