正确使用stash \ unstash到其他目录 [英] Correct usage of stash\unstash into a different directory

查看:1026
本文介绍了正确使用stash \ unstash到其他目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个阶段中,我需要在构建完成后复制两个文件夹的内容并将其复制到另一个目录.

In one of my stages I need to copy the contents of two folders after a build is completed and copy to a different directory.

我实际上是在将自由式作业转换为管道,并且一直在使用工件部署程序插件.仔细阅读,看来存储和取消存储命令应该可以帮助我实现目标.

I am actually converting a freestyle job to pipeline, and have been using the artifact deployer plugin. Reading around, it looks like stash and unstash commands should help with what I want to achieve.

请问有人可以验证下面的方法是否正确吗?

Can someone verify if this is the correct approach below please?

stage('Build') {
      steps {
        sh '''
          gulp set-staging-node-env
          gulp prepare-staging-files
          gulp webpack
        '''
        stash includes: '/dist/**/*', name: 'builtSources'
        stash includes: '/config/**/*', name: 'appConfig'
        dir('/some-dir') {
          unstash 'builtSources'
          unstash 'appConfig'
        }
      }
    }

如果我在一个阶段中更改dir,是否意味着此后所有其他阶段都将尝试从该目录执行命令,或者它们会回到使用工作区默认位置的方式?

If I change dir in one stage, does that mean all other stages thereafter will try to execute commands from that directory, or do they do back to using the workspace default location?

谢谢

编辑

我已经意识到我真正想做的是将构建的源代码复制到另一个节点(运行另一个OS).因此,在我的代码段中,我共享了我要切换目录的位置,该目录实际上位于我已设置的另一台计算机(节点)上.

I have realised what I actually want to do is to copy built sources to a different node (running a different OS). So in my snippet I have shared, where I am switching directories, that directory is actually to be on a different machine (node) that I have setup.

我需要用node('my-node-name')块包装dir()块吗?我正在努力寻找例子.

Would I need to wrap the dir() block with a node('my-node-name') block? Im struggling to find examples.

谢谢

推荐答案

我希望它是这样的:

stash includes: 'dist/**/*', name: 'builtSources'

stash includes: 'config/**/*', name: 'appConfig'

其中dist和config是工作区路径中的目录,因此它应该是上面的相对路径.

where dist and config are the directories in the workspace path, so it should be a relative path like above.

Rest似乎还不错,仅提及路径"/some-dir"应该由jenkins用户(用于运行jenkins守护程序的用户)可写.

Rest seems alright, only to mention that path "/some-dir" should be writable by jenkins user (user used to run jenkins daemon).

是的,当它退出dir块时,它会退回到其随后封闭的工作空间路径(在本例中为默认).

And yes it falls back to its then enclosing workspace path (in this case default) when it exits dir block.

编辑

因此,当您存储路径时,可以在管道的任何后续步骤中取消隐藏该路径.所以可以,您可以将dir块放在node('<nodename>')块下面.

So when you stash a path, it is available to be unstashed at any step later in the pipeline. So yes, you could put dir block under a node('<nodename>') block.

您可以添加以下内容:

stage('Move the Build'){
  node('datahouse'){
    dir('/opt/jenkins_artifacts'){
      unstash 'builtSources'
      unstash 'appConfig'
    }
  }
}

这篇关于正确使用stash \ unstash到其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆