Extract Git URL from file using Powershell - powershell

1/ I need to extract in a folder a specific part of url. The url is in the subfolder named ".git" and I use the command:
git remote get-url --all origin
url look like this:
- git#servername:do-amont/production/ei2/nova/migration-devfactory.git
- ssh://servername.domain.com:30272/do-amont/production/ei2/nova/migration-devfactory.git
- https: //gitlab-review-dev-jxuor3.openshift-intra-dev.domain. com/do-amont/production/ei2/nova/migration-devfactory.git
the part I need is
do-amont/production/ei2/nova/migration-devfactory.git
After that I need to put the extracting url on this command
git remote set-url --add origin ssh://git#l203ei3007.domain.com:30272/do-amont/production/ei2/nova/migration-devfactory.git
I need to automatise these step on powershell

You can get the URL from the git config for a specified remote via the git config git command-line command, as long as you run it from within the directory with the .git folder.
So you could do something like this (assumes the part of the URL you want to keep is always after a colon):
$GitURL = (git config remote.origin.url).split(':')[1]
git remote set-url --add origin "ssh://git#l203ei3007.domain.com:30272/$GitURL"

Related

Cannot clone git repository in command line script task in Azure DevOps Pipelines

I created azure devops pipeline where I need to download code from another git repository. As per recommended solution I've read somewhere, I added a command line script task with git clone command. Unfortunatelly this doesn't work.
The error that I get is:
remote: TF200016: The following project does not exist: My0Test0Project. Verify that the name of the project is correct and that the project exists on the specified Azure DevOps Server.
fatal: repository 'https://dev.azure.com/myCompany/My0Test0Project/_git/Service.Azure.Core/' not found
My project in Azure has spaces, maybe there is a bug in azure related to that? Does anybody knows any workarounds?
This is some code that I have tried already:
git -c http.extraheader="AUTHORIZATION: Basic bXl1c2VyOmxtNjRpYTYzb283bW1iYXp1bnpzMml2eWxzbXZoZXE2azR1b3V2bXdzbnl5b3R5YWlnY2E=" clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git clone https://oauth:lm64ia63oo7mmbazunzs2ivylsmvheq6k4uouvmwsnyyotyaigca#dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git clone https://test:$(System.AccessToken)#dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
The reason is because you need to add the system access token so that Azure can have access to the external repo. (your credentials need access to that repo)
NOTE:
I wrapped my URL in quotes to escape the % signs in the URL string because Powershell treats those as variables otherwise.
- powershell: |
git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" "https://{YOUR PIPELINE URL}"
displayName: '{YOUR PIPELINE NAME}'
I had the same issue from a bash script and solved it by escaping the % character with %%.
So, you can use this :
git clone https://test:$(System.AccessToken)#dev.azure.com/myCompany/My%%20Test%%20Project/_git/Service.Azure.Core
Can you try to change your Command Line task to something like this one?
git clone --single-branch --branch $(branchName) https://$(gitUserName):$(gitPassword)#dev.azure.com/myCompany/My%20Test%20Project/_git
Where $(gitUserName) and $(gitPassword) configured as Alternate git credentials in
your Azure DevOps account.
Also wanted to ask about ending of git repository URL:
".../_git/Service.Azure.Core", you are trying to specify which folder to clone or maybe working directory? You can also try your previous code without that ending, just
https://dev.azure.com/myCompany/My%20Test%20Project/_git
I tried this from Powershell task and it worked
Its very simple just use
- powershell: |
git config user.email "$(Build.RequestedForEmail)"
git config user.name "$(Build.RequestedFor)"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone https://<org_Name>.visualstudio.com/<project_name>/_git/<repository_name>;
displayName: "<your task display name>"
This will happen when your path has space characters in it.
The workaround for this is to not use %20 in your URL and use actual space characters instead. Since your URL now has space characters, also make sure that your URL is wrapped inside double quotes.
So your
git clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core/
should be
git clone "https://dev.azure.com/myCompany/My Test Project/_git/Service.Azure.Core/"

No author information was supplied by the version control system

I just updated my Xcode to version 10.2 (10E125).
A moment I want to commit, I get this message:
After I click on fix:
I have filled in the information, but I’m still getting that message above.
What's the reason?
You can set the author information using Terminal. It might be possible that xCode has the author data but it's not actually set in Git config.
Setting your Git username for every repository on your computer
1) Open Terminal.
2) Set a Git username:
$ git config --global user.name "Mona Lisa"
3) Confirm that you have set the Git username correctly:
$ git config --global user.name
> Mona Lisa
Setting your Git username for a single repository
1) Open Terminal.
2) Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.
3) Set a Git username:
$ git config user.name "Mona Lisa"
4) Confirm that you have set the Git username correctly:
$ git config user.name
> Mona Lisa
Source: https://help.github.com/en/articles/setting-your-username-in-git
Click on "Fix" and provide your Git username and email. This fixed my issue.

Polymer 2.0 upload to GitHub-Pages

I have problem with uploading my Polymer component into gh pages.
I'm try this from tutorial:
# git clone the Polymer tools repository somewhere outside of your
# element project
git clone git://github.com/Polymer/tools.git
# Create a temporary directory for publishing your element and cd into it
mkdir temp && cd temp
# Run the gp.sh script. This will allow you to push a demo-friendly
# version of your page and its dependencies to a GitHub pages branch
# of your repository (gh-pages). Below, we pass in a GitHub username
# and the repo name for our element
../tools/bin/gp.sh <username> <test-element>
# Finally, clean-up your temporary directory as you no longer require it
cd ..
rm -rf temp
But it's not working.
In terminal I have this errors:
There is something I'm, missing?
Here is your problem:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
For the script to run as intended, you need to add your public ssh key to your github project. Settings -> Deploy keys -> Add deploy Key.
Alternatively, you can manually execute the steps in gp.sh that involve pulling from and pushing to github.
If you don't feel like splitting up the script, try running the commands manually, that should work. The only multi-line command in the script is this one:
echo "{
\"directory\": \"components\"
}
" > .bowerrc
Good luck.

Pushing entire Rundeck configuration to github

I want to push entire Rundeck configuration to Github. Is there any way for doing this ?
Considering the Rundeck configuration layout, all you would need to do is:
cd $RDECK_BASE
git init .
git remote add origin /url/new/empty/GitHub/repo
echo '*'>.gitignore
echo '!/etc/'>.gitignore
echo '!/server/'>.gitignore
echo '/server/*'>.gitignore
echo '!/server/config/'>.gitignore
git add .
git commit -m "Rundeck config"
git push -u master
Basically, you need to ignore what is not configuration before adding everything else (ie, the config files), and pushing to your own GitHub repo.
Make sure those files don't have sensitive credential information in them though (or at least push them to a private GitHub repo if you have one)

using capistrano on a shared host, how to set the temporary directory for repo access

cap is trying to create this location on my server to access my git repo (on bitbucket). Unfortunately this is a shared host, and the ssh keys are in my user directory, not in /tmp…. so this fails:
GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/doman.com/git-ssh.sh /usr/bin/env git ls-remote
Can I configure this tmp dir to be in my home dir?
According to the Capistrano Github page you should set the :tmp_dir variable to a directory on your homepath like /home/user/tmp/capistrano
For example:
set :tmp_dir, '/home/user/tmp/capistrano'