如何在expect脚本中检查Linux提示符?

时间:2018-03-19 17:24:48

标签: jenkins expect

我正在尝试编写一个可以在Jenkins作业中运行的expect脚本来自动克隆GitLFS repo。当我克隆一个GitLFS回购时,我得到了

user@hostname $ git clone http://github.company.com/user/test123.git

我得到了

Username for 'https://github.company.com': myuser
Password for 'https://myuser@github.company.com':
remote: Counting objects: 66, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 66 (delta 2), reused 8 (delta 2), pack-reused 58
Unpacking objects: 100% (66/66), done.
Downloading bin/at.exe (29.50 KB)
Username for 'https://gitlfs.company.com': myuser
Password for 'https://myuser@gitlfs.company.com':
Downloading bin/foo.exe (29.50 KB)
Username for 'https://gitlfs.company.com': myuser
Password for 'https://myuser@gitlfs.company.com':
Downloading bin/bar.exe (29.50 KB)
Username for 'https://gitlfs.company.com': myuser
Password for 'https://myuser@gitlfs.company.com':
user@hostname $

根据回购,我不知道有多少次我会被提示输入用户名/密码。在上面的回购中,我得到了4次。所以我想编写一个期望脚本

send "git clone http://github.company.com/user/test123.git"
while NOT_EQUAL_TO_PROMPT {
  expect "Username for 'https://gitlfs.company.com':"
  send myuser
  expect "Password for 'https://myuser@gitlfs.company.com':"
  send mypassword
}

关于" NOT_EQUAL_TO_PROMPT"的任何提示可能看起来像?谢谢!

1 个答案:

答案 0 :(得分:1)

原来@Stephen Newell部分正确。 Jenkins有一个GitLFS插件,可以为我提取GitLFS对象,如Git LFS setup in jenkins中所述。我所要做的就是将我的信息存储在Jenkins中并在Git设置中使用它们。谢谢!