Pulling or pushing to github from a TeamCity agent

Completed

Hello.

I use a TeamCity build agent to build code. When I built it I change a file, commit it and want to push it back. I don't want to use my password in the Build Step's command line. So, I use the SSH Exec runner type. I made a key, uploaded the public one to github and the private one to TeamCity. I see my id_rsa key is used in VCS root and in the Build agent.

I create a VCS Root: Type of VCS: Git, Fetch URL: ssh://git@github.com/repo_name.git, Username: git, Auth method: Uploaded key, Username: git, Uploaded key: id_rsa. It works, the repo clones well.

Futher I want to update another branch by hand, commit to it and push it. So, I create the build step: Authentification method: Uploaded key Target: github.com Username: git Select key: id_rsa Commands: git fetch ssh://git@github.com/repo_name.git master. Here I tried different urls, but nothing works with error:

Step 1/6: Update (SSH Exec)

  Permanently added 'github.com' (RSA) to the list of known hosts.
  Executing commands: git fetch ssh://git@github.com/izdeveloper/jsoft.git watchtower on host [github.com]
  Invalid command: 'git fetch ssh://git@github.com/repo_name.git master'
   You appear to be using ssh to clone a git:// URL.
   Make sure your core.gitProxy config option and the
   GIT_PROXY_COMMAND environment variable are NOT set.
  SSH exit-code 1
  Step Update (SSH Exec) failed
 
So, how can I pull a branch and after push it using a script? Is it possible?
If not should I use the auth via password? In this way, is there a possibility to save the password which I use in the VCS settings in a environment variable to use it in the console command of a build step?
0
8 comments

Hi Dgordenin in your build step you are doing a git fetch but first shouldn't you do a git clone ssh://git@github.com/repo_name.git

Depending on your checkout mode (https://www.jetbrains.com/help/teamcity/vcs-checkout-mode.html#) only the agent side option will actually do a clone on the agent for you, where you can perform further git actions on that cloned repo. If you use a checkout mode like server side it only transfers the files from your git repo.

 

 

 

1

Hi, Dylan Munyard .

My VCS checkout mode is "Always checkout files on agent".

I set my build step "SSH Exec" to "git clone ssh://git@github.com/repo_name.git".But still have the following error:

Step 1/6: Update (SSH Exec)

  Permanently added 'github.com' (RSA) to the list of known hosts.
  Executing commands: git clone ssh://git@github.com/repo_name.git on host [github.com]
  Invalid command: 'git clone ssh://git@github.com/repo_name.git'
   You appear to be using ssh to clone a git:// URL.
   Make sure your core.gitProxy config option and the
   GIT_PROXY_COMMAND environment variable are NOT set.
0

Dgordenin I think I see the problem, it says in the message "Executing commands on host [github.com]" which I think means SSH Exec step is for executing remote commands, not as a 'SSH wrapper'. I think what you want is the 'SSH agent' feature instead, this one is a 'Build Feature' so open it from your build settings and add it and select your key.

Then add a build step which executes on the command line and try now git clone ...

 

1

Dylan,

I have a Build feature "SSH agent" with uploaded key id_rsa.

Which type of build step should i create? I have a "SSH Exec" - result is the error above. I have "Command line" - result is error:

Cloning into 'test'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Process exited with code 128
0

I'm on Windows, so I have a PowerShell step:

In the build output I have:

15:01:27
Cloning into 'E:\BuildAgent1\work\7c1f1231fdb4fc7d/AddOnPacks/Schema.Core/dev'...
15:01:28
Warning: Permanently added 'hostname,IP' (RSA) to the list of known hosts.

1

Do you have the "Command Line" build step?

VCS checkout mode "Always checkout files on agent"?

0

Yes, I have just set up a build that does a VCS checkout on the agent then does a git clone.

I think you are making progress, you were using the wrong build step before now you have a different error: Host key verification failed. Seems like a Git issue now - not TC - but maybe a TC official will help if you believe it's a TeamCity problem.

0

Thank you, finally moved the ssh keys to the /root/.ssh and got it working.

1

Please sign in to leave a comment.